PMA\libraries\DatabaseInterface::cacheTableContent PHP Méthode

cacheTableContent() public méthode

Set an item in table cache using dot notation.
public cacheTableContent ( array $contentPath, mixed $value ) : void
$contentPath array Array with the target path
$value mixed Target value
Résultat void
    public function cacheTableContent($contentPath, $value)
    {
        $loc =& $this->_table_cache;
        if (!isset($contentPath)) {
            $loc = $value;
            return;
        }
        while (count($contentPath) > 1) {
            $key = array_shift($contentPath);
            // If the key doesn't exist at this depth, we will just create an empty
            // array to hold the next value, allowing us to create the arrays to hold
            // final values at the correct depth. Then we'll keep digging into the
            // array.
            if (!isset($loc[$key]) || !is_array($loc[$key])) {
                $loc[$key] = array();
            }
            $loc =& $loc[$key];
        }
        $loc[array_shift($contentPath)] = $value;
    }

Usage Example

Exemple #1
0
 /**
  * Counts and returns (or displays) the number of records in a table
  *
  * @param bool $force_exact whether to force an exact count
  *
  * @return mixed the number of records if "retain" param is true,
  *               otherwise true
  */
 public function countRecords($force_exact = false)
 {
     $is_view = $this->isView();
     $db = $this->_db_name;
     $table = $this->_name;
     if ($this->_dbi->getCachedTableContent("{$db}.{$table}.ExactRows") != null) {
         $row_count = $this->_dbi->getCachedTableContent("{$db}.{$table}.ExactRows");
         return $row_count;
     }
     $row_count = false;
     if (!$force_exact) {
         if ($this->_dbi->getCachedTableContent("{$db}.{$table}.Rows") == null && !$is_view) {
             $tmp_tables = $this->_dbi->getTablesFull($db, $table);
             if (isset($tmp_tables[$table])) {
                 $this->_dbi->cacheTableContent("{$db}.{$table}", $tmp_tables[$table]);
             }
         }
         if ($this->_dbi->getCachedTableContent("{$db}.{$table}.Rows") != null) {
             $row_count = $this->_dbi->getCachedTableContent("{$db}.{$table}.Rows");
         } else {
             $row_count = false;
         }
     }
     // for a VIEW, $row_count is always false at this point
     if (false !== $row_count && $row_count >= $GLOBALS['cfg']['MaxExactCount']) {
         return $row_count;
     }
     if (!$is_view) {
         $row_count = $this->_dbi->fetchValue('SELECT COUNT(*) FROM ' . Util::backquote($db) . '.' . Util::backquote($table));
     } else {
         // For complex views, even trying to get a partial record
         // count could bring down a server, so we offer an
         // alternative: setting MaxExactCountViews to 0 will bypass
         // completely the record counting for views
         if ($GLOBALS['cfg']['MaxExactCountViews'] == 0) {
             $row_count = 0;
         } else {
             // Counting all rows of a VIEW could be too long,
             // so use a LIMIT clause.
             // Use try_query because it can fail (when a VIEW is
             // based on a table that no longer exists)
             $result = $this->_dbi->tryQuery('SELECT 1 FROM ' . Util::backquote($db) . '.' . Util::backquote($table) . ' LIMIT ' . $GLOBALS['cfg']['MaxExactCountViews'], null, DatabaseInterface::QUERY_STORE);
             if (!$this->_dbi->getError()) {
                 $row_count = $this->_dbi->numRows($result);
                 $this->_dbi->freeResult($result);
             }
         }
     }
     if ($row_count) {
         $this->_dbi->cacheTableContent("{$db}.{$table}.ExactRows", $row_count);
     }
     return $row_count;
 }