За последние 24 часа нас посетил 59551 программист и 1851 робот. Сейчас ищут 2194 программиста ...

Ошибка в стандартах.

Тема в разделе "PHP и базы данных", создана пользователем 715kg, 8 мар 2013.

  1. 715kg

    715kg Активный пользователь

    С нами с:
    2 мар 2013
    Сообщения:
    147
    Симпатии:
    0
    Здравствуйте. Не работает кэширование базы данных. Не пойму почему. Ошибки

    Strict Standards: Declaration of dateBase::getRow() should be compatible with that of controlDB::getRow() in /home/wm5142/domains/gameamx.ru/public_html/testdvig/boot/db_cache.class.php on line 258

    Код

    Код (Text):
    1. <?php
    2.  if (!defined('ACCESS')) {
    3.     header('Location: /');
    4.     exit;
    5. }
    6. define('NOW_TIME', time());
    7.  
    8.  
    9.  
    10.  
    11. class dateBase extends controlDB
    12. {
    13.     var $prefix = '';
    14.    
    15.     private $dir = 'tmp/mysql';
    16.     private $index_file = 'index';
    17.     private $index = array('drop' => array());
    18.     private $cached = array();
    19.     private $pointer = array();
    20.     private $hashDrop = array();
    21.     private $flush_by = array('INSERT', 'UPDATE', 'DELETE', 'REPLACE', 'ALTER');
    22.     private $real_time_tables = array('online', 'comments', 'plugins', 'logs', 'reffers');
    23.     private $real_time_func = array('NOW', 'UNIX_TIMESTAMP');
    24.     private $no_cache_timeout = 300;
    25.  
    26.     function __construct()
    27.     {
    28.         require_once ROOT . 'etc/db.config.php';
    29.         parent::connect($dbhost, $dbuser, $dbpass, $dbname);
    30.        
    31.         define("DB_PREFIX", $prefix);
    32.         define("USER_PREFIX", $user_prefix);
    33.         define("USER_DB", $user_db);
    34.        
    35.         if (!is_dir(ROOT.'tmp/mysql/')) {mkdir(ROOT.'tmp/mysql/', 0777); @chmod_R(ROOT.'tmp/mysql/', 0777);}
    36.        
    37.         $this->dir = ROOT.'tmp/mysql/';
    38.        
    39.         if (file_exists($this->dir.$this->index_file)) include_once($this->dir.$this->index_file);
    40.         unset($dbhost, $dbuser, $dbpass, $prefix, $user_prefix, $user_db);
    41.     }
    42.    
    43.     function __destruct()
    44.     {
    45.         if (sizeof($this->index['drop']) > 0)
    46.         {
    47.             $this->index['drop'] = array_unique($this->index['drop']);
    48.             foreach ($this->index['drop'] AS $hash)
    49.             {
    50.                 unset($this->index['lifetime'][$hash]);
    51.                 @unlink($this->dir.$hash);
    52.             }
    53.             $this->index['drop'] = array();
    54.         }
    55.        
    56.         $index = '<?php $this->index='.$this->arr2str($this->index).'; ?>';
    57.         $this->write_file($this->index_file, $index);
    58.     }
    59.    
    60.  
    61.     function query($query)
    62.     {
    63.         $hash = md5 (preg_replace('~([0-9]{10})~', '', $query));
    64.         $is_realtime = preg_match('~([0-9]{10})~', $query);
    65.         $is_cached = false;
    66.         $do = trim(strtoupper(mb_substr($query, 0, strpos($query, ' '))));
    67.         if (!isset($this->cached[$hash]))
    68.         {
    69.             if ($do == 'SELECT' or $do == 'DO')
    70.             {
    71.                 preg_match_all('~' . $this->prefix . '_([^\s`]+)~i', $query, $match);
    72.                 $tables =& $match[1]; unset ($match);
    73.                
    74.                 if (sizeof($tables) > 0 && sizeof(array_intersect($tables, $this->real_time_tables)) == 0)
    75.                 {
    76.                     if (in_array($hash, $this->index['drop']) or !file_exists($this->dir.$hash))
    77.                     {
    78.                         foreach ($tables AS $table)
    79.                         {
    80.                             $this->index['links'][$table][$hash] = array_diff($tables, array($table));
    81.                         }
    82.                         $this->index['times'][$hash] = NOW_TIME;
    83.                     }
    84.                     else
    85.                     {
    86.                         $modified =& $this->index['times'][$hash];
    87.                         if ($is_realtime or preg_match('~('.implode('|', $this->real_time_func).')~i', $query))
    88.                         {      
    89.                             if ($this->no_cache_timeout && (NOW_TIME - $modified) < $this->no_cache_timeout) $is_cached = true;
    90.                             else
    91.                             {
    92.                                 $this->index['times'][$hash] = NOW_TIME;
    93.                             }
    94.                         }
    95.                         else $is_cached = true;
    96.                     }
    97.                     if ($is_cached) $this->readcache($hash);
    98.                     else
    99.                     {
    100.                         $mysql = parent::doQuery($query, false, $this->prefix);
    101.                        
    102.                         if ($mysql)
    103.                         {
    104.                             while ($row = parent::getRow($mysql)) $this->cached[$hash]['data'][] = $row;
    105.                             $this->cached[$hash]['sizeof'] = parent::numRows($mysql);
    106.                             if (!$this->cached[$hash]['sizeof']) $this->cached[$hash]['sizeof'] = 0;
    107.                             $this->pointer[$hash] = 0;
    108.                             $this->iQuery_id = $hash;
    109.                             $this->write_cache($hash);
    110.                         }
    111.                     }
    112.                     return $hash;
    113.                 }
    114.             }
    115.            
    116.        
    117.             if (in_array($do, $this->flush_by))
    118.             {   //RESET CACHE
    119.                
    120.                 if (preg_match('~' . $this->prefix . '_([^\s`]+)~i', $query, $match))
    121.                 {      
    122.                     $table =& $match[1]; unset ($match);               
    123.                     if (isset($this->index['links'][$table]))
    124.                     {
    125.                         foreach ($this->index['links'][$table] AS $h => $link)
    126.                         {
    127.                             if(!isset($this->hashDrop[$h]))
    128.                             {
    129.                                 foreach ($link AS $tbl)
    130.                                 {
    131.                                     unset($this->index['links'][$tbl][$h]);
    132.                                 }
    133.                                 $this->index['drop'][] = $h;
    134.                                 $this->hashDrop[$h] = true;
    135.                             }
    136.                         }
    137.                     }
    138.                 }
    139.             }
    140.             return parent::doQuery($query, false, $this->prefix);
    141.         }
    142.         return $hash;
    143.  
    144.     }
    145.  
    146.     function arr2str (&$arr, $depth = 0)
    147.     {
    148.             $ret = array();
    149.             if (is_array($arr) && sizeof($arr) > 0)
    150.             {
    151.                     foreach ($arr AS $key => $value)
    152.                     {
    153.                             $key = str_replace("'", "\'", $key);
    154.                             if (is_array($value)) $ret[] = "'{$key}'=>".$this->arr2str($value, $depth+1);
    155.                             elseif (is_int($value)) $ret[] = "'{$key}'=>$value";
    156.                             else
    157.                             {
    158.                                     if (is_string($value)) $value = str_replace("'", '"', $value);
    159.                                     $ret[] = "'{$key}'=>'".strval($value)."'";
    160.                             }
    161.                     }
    162.             }
    163.             return 'array('.implode(',', $ret).')';
    164.     }
    165.  
    166.     function freeResult($resource)
    167.     {
    168.         return parent::freeResult($resource);
    169.     }
    170.    
    171.     function &getRow($query_id)
    172.     {
    173.         $ret = false;
    174.         if (isset($this->cached[$query_id]))
    175.         {
    176.             if ($this->pointer[$query_id] < $this->cached[$query_id]['sizeof'])
    177.             {
    178.                 $ret = $this->cached[$query_id]['data'][$this->pointer[$query_id]];
    179.                 $this->pointer[$query_id]++;
    180.             }
    181.         }
    182.         else $ret = parent::getRow($query_id);
    183.        
    184.         return $ret;
    185.     }
    186.    
    187.     function fetchRow($query_id)
    188.     {
    189.         $ret =& $this->fetch_assoc($query_id);
    190.         return $ret ? array_values($ret) : $ret;
    191.     }
    192.    
    193.     function &fetch_assoc ($query_id = -1)
    194.     {
    195.         $ret = false;
    196.         if (isset($this->cached[$query_id]))
    197.         {
    198.             if ($this->pointer[$query_id] < $this->cached[$query_id]['sizeof'])
    199.             {
    200.                 $ret = $this->cached[$query_id]['data'][$this->pointer[$query_id]];
    201.                 $this->pointer[$query_id]++;
    202.             }
    203.         }
    204.         elseif ($query_id != -1) $ret = parent::getRow($query_id);
    205.         return $ret;
    206.     }
    207.    
    208.     function numRows($query_id)
    209.     {
    210.         if (isset($this->cached[$query_id])) return $this->cached[$query_id]['sizeof'];
    211.         else return parent::numRows($query_id);
    212.     }
    213.    
    214.  
    215.     private function readcache ($hash)
    216.     {
    217.         include_once($this->dir.$hash);
    218.         $this->pointer[$hash] = 0;
    219.         $this->iQuery_id = $hash;
    220.     }
    221.    
    222.     private function write_cache ($hash)
    223.     {
    224.         $data = "<?php \$this->cached['$hash']=".$this->arr2str($this->cached[$hash]).'; ?>';
    225.         $this->write_file($hash, $data);
    226.     }
    227.    
    228.     private function write_file($filename, &$content)
    229.     {
    230.         ignore_user_abort(1);
    231.         $lockfile = $this->dir.$filename . '.lock';
    232.         if (file_exists($lockfile) && (time() - filemtime($lockfile)) > 5) @unlink($lockfile);
    233.         $lock_ex = @fopen($lockfile, 'x');
    234.         for ($i=0; ($lock_ex === false) && ($i < 20); $i++)
    235.         {
    236.             clearstatcache();
    237.             usleep(rand(5, 15));
    238.             $lock_ex = @fopen($lockfile, 'x');
    239.         }
    240.        
    241.         $success = false;
    242.         if ($lock_ex !== false)
    243.         {
    244.             $fp = @fopen($this->dir.$filename, 'wb');
    245.             if (@fwrite($fp, $content)) $success = true;
    246.             @fclose($fp);
    247.             fclose($lock_ex);
    248.             @unlink($lockfile);
    249.         }
    250.         ignore_user_abort(0);
    251.         return $success;
    252.     }
    253. }
    254.  
    255.  
    256. $db = new dateBase();
     
  2. runcore

    runcore Старожил

    С нами с:
    12 окт 2012
    Сообщения:
    3.625
    Симпатии:
    158
    в тексте ошибки вроде все понятно написано.
    dateBase::getRow() должна быть совместима с controlDB::getRow() . тоесть описана аналогично.
    кода класса controlDB вы не привели. так что точно сказать нельзя.
    сравните эти метожды и сделайте их одинаковыми с точки зрения кол-ва и типа параметров и т.д.
     
  3. jenya777777

    jenya777777 Активный пользователь

    С нами с:
    16 мар 2010
    Сообщения:
    562
    Симпатии:
    0
    Какие параметры у тебя передаются в родительский getRow?