За последние 24 часа нас посетили 73666 программистов и 3106 роботов. Сейчас ищут 1422 программиста ...

как решить проблему

Тема в разделе "PHP для новичков", создана пользователем aceman17, 3 май 2011.

  1. aceman17

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

    С нами с:
    3 май 2011
    Сообщения:
    23
    Симпатии:
    0
    Fatal error: [includes/functions_group.php(24)] in /var/www/torrent/data/www/x360box-clan.ru/includes/db/mysql.php on line 800
     
  2. Padaboo

    Padaboo Старожил
    Команда форума Модератор

    С нами с:
    26 окт 2009
    Сообщения:
    5.242
    Симпатии:
    1
    Зачем 3 темы?
     
  3. siiXth

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

    С нами с:
    14 мар 2010
    Сообщения:
    1.447
    Симпатии:
    1
    800 строка в /var/www/torrent/data/www/x360box-clan.ru/includes/db/mysql.php
     
  4. aceman17

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

    С нами с:
    3 май 2011
    Сообщения:
    23
    Симпатии:
    0
    извеняюсь
     
  5. aceman17

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

    С нами с:
    3 май 2011
    Сообщения:
    23
    Симпатии:
    0
    вот trigger_error($msg, E_USER_ERROR);
     
  6. Nabai

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

    С нами с:
    3 май 2011
    Сообщения:
    51
    Симпатии:
    0
    весь файл скинул бы лучше
     
  7. aceman17

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

    С нами с:
    3 май 2011
    Сообщения:
    23
    Симпатии:
    0
    спойлер не работает
     
  8. Nabai

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

    С нами с:
    3 май 2011
    Сообщения:
    51
    Симпатии:
    0
    В СПОЙЛЕР БЛЕАТЬ!
    Код (Text):
    1.  
    2. [php][/php]
    3. КУ
     
  9. aceman17

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

    С нами с:
    3 май 2011
    Сообщения:
    23
    Симпатии:
    0
    PHP:
    1. <?php
    2.  
    3. /***************************************************************************
    4.  *  MySQL Layer (slightly based on phpBB)
    5.  *  (c) Meithar
    6.  ***************************************************************************/
    7.  
    8. if (!defined('SQL_DEBUG')) die(basename(__FILE__) .": 'SQL_DEBUG' undefined");
    9.  
    10. define('SQL_LAYER',          'mysql');
    11. define('DEFAULT_QUERY_TYPE', 'buffered');   //  buffered, unbuffered
    12.  
    13. class sql_db
    14. {
    15.     var $cfg            = array();
    16.     var $link           = null;
    17.     var $result         = null;
    18.     var $selected_db    = null;
    19.  
    20.     var $pconnect       = false;
    21.     var $locked         = false;
    22.     var $locks          = array();
    23.  
    24.     var $num_queries    = 0;
    25.     var $sql_starttime  = 0;
    26.     var $sql_inittime   = 0;
    27.     var $sql_timetotal  = 0;
    28.     var $cur_query_time = 0;
    29.  
    30.     var $log_file       = 'sql_queries';
    31.     var $log_counter    = 0;
    32.  
    33.     var $dbg            = array();
    34.     var $dbg_id         = 0;
    35.     var $dbg_enabled    = false;
    36.     var $cur_query      = null;
    37.  
    38.     var $do_explain     = false;
    39.     var $explain_hold   = '';
    40.     var $explain_out    = '';
    41.  
    42.     var $shutdown       = array();
    43.  
    44.     /**
    45.     * Constructor
    46.     */
    47.     function sql_db ($cfg)
    48.     {
    49.         $this->dbg_enabled = (SQL_DEBUG && DBG_USER && (!empty($_COOKIE['sql_log']) || !empty($_COOKIE['explain'])));
    50.         $this->do_explain  = ($this->dbg_enabled && !empty($_COOKIE['explain']));
    51.         $this->pconnect    = $cfg['persist'];
    52.         $this->cfg         = $cfg;
    53.     }
    54.  
    55.     /**
    56.     * Initialize connection
    57.     */
    58.     function init ()
    59.     {
    60.         // Connect to server
    61.         $this->link = $this->connect();
    62.  
    63.         // Select database
    64.         $this->selected_db = $this->select_db();
    65.  
    66.         // Set charset
    67.         if ($this->cfg['charset'] && !$this->sql_query("SET NAMES {$this->cfg['charset']}"))
    68.         {
    69.             die("Could not set charset {$this->cfg['charset']}");
    70.         }
    71.  
    72.         $this->num_queries = 0;
    73.         $this->sql_inittime = $this->sql_timetotal;
    74.     }
    75.  
    76.     /**
    77.     * Open connection
    78.     */
    79.     function connect ()
    80.     {
    81.         $this->cur_query = ($this->pconnect ? 'p' : '') . "connect to: {$this->cfg['dbhost']}";
    82.         $this->debug('start');
    83.  
    84.         $connect_type = ($this->pconnect) ? 'mysql_pconnect' : 'mysql_connect';
    85.  
    86.         if (!$link = @$connect_type($this->cfg['dbhost'], $this->cfg['dbuser'], $this->cfg['dbpasswd']))
    87.         {
    88.             $server = (DBG_USER) ? $this->cfg['dbhost'] : '';
    89.             header("HTTP/1.0 503 Service Unavailable");
    90.             die("Could not connect to the server $server");
    91.         }
    92.  
    93.         register_shutdown_function(array(&$this, 'sql_close'));
    94.  
    95.         $this->debug('stop');
    96.         $this->cur_query = null;
    97.  
    98.         return $link;
    99.     }
    100.  
    101.     /**
    102.     * Select database
    103.     */
    104.     function select_db ()
    105.     {
    106.         $this->cur_query = "select db: {$this->cfg['dbname']}";
    107.         $this->debug('start');
    108.  
    109.         if (!@mysql_select_db($this->cfg['dbname'], $this->link))
    110.         {
    111.             $database = (DBG_USER) ? $this->cfg['dbhost'] : '';
    112.             die("Could not select database $database");
    113.         }
    114.  
    115.         $this->debug('stop');
    116.         $this->cur_query = null;
    117.  
    118.         return $this->cfg['dbname'];
    119.     }
    120.  
    121.     /**
    122.     * Base query method
    123.     */
    124.     function sql_query ($query, $type = DEFAULT_QUERY_TYPE)
    125.     {
    126.         if (!is_resource($this->link))
    127.         {
    128.             $this->init();
    129.         }
    130.         if (is_array($query))
    131.         {
    132.             $query = $this->build_sql($query);
    133.         }
    134.         $this->cur_query = $query;
    135.         $this->debug('start');
    136.  
    137.         $query_function = ($type === 'unbuffered') ? 'mysql_unbuffered_query' : 'mysql_query';
    138.  
    139.         if (!$this->result = $query_function($query, $this->link))
    140.         {
    141.             $this->log_error();
    142.         }
    143.  
    144.         $this->debug('stop');
    145.         $this->cur_query = null;
    146.  
    147.         $this->num_queries++;
    148.  
    149.         return $this->result;
    150.     }
    151.  
    152.     /**
    153.     * Execute query WRAPPER (with error handling)
    154.     */
    155.     function query ($query, $type = DEFAULT_QUERY_TYPE, $err_msg = '')
    156.     {
    157.         if (!$result = $this->sql_query($query, $type))
    158.         {
    159.             $this->trigger_error($err_msg);
    160.         }
    161.  
    162.         return $result;
    163.     }
    164.  
    165.     /**
    166.     * Return number of rows
    167.     */
    168.     function sql_numrows ($result = false)
    169.     {
    170.         $num_rows = false;
    171.  
    172.         if ($result OR $result = $this->result)
    173.         {
    174.             $num_rows = is_resource($result) ? mysql_num_rows($result) : false;
    175.         }
    176.  
    177.         return $num_rows;
    178.     }
    179.  
    180.     /**
    181.     * Return number of affected rows
    182.     */
    183.     function sql_affectedrows ()
    184.     {
    185.         return is_resource($this->link) ? mysql_affected_rows($this->link) : -1;
    186.     }
    187.  
    188.     // Report
    189.     /**
    190.     * Fetch current field
    191.     */
    192.     function sql_fetchfield($field, $rownum = -1, $query_id = 0)
    193.     {
    194.         if(!$query_id)
    195.         {
    196.             $query_id = $this->query_result;
    197.         }
    198.         if($query_id)
    199.         {
    200.             if($rownum > -1)
    201.             {
    202.                 $result = @mysql_result($query_id, $rownum, $field);
    203.             }
    204.             else
    205.             {
    206.                 if(empty($this->row[$query_id]) && empty($this->rowset[$query_id]))
    207.                 {
    208.                     if($this->sql_fetchrow())
    209.                     {
    210.                         $result = $this->row[$query_id][$field];
    211.                     }
    212.                 }
    213.                 else
    214.                 {
    215.                     if($this->rowset[$query_id])
    216.                     {
    217.                         $result = $this->rowset[$query_id][0][$field];
    218.                     }
    219.                     else if($this->row[$query_id])
    220.                     {
    221.                         $result = $this->row[$query_id][$field];
    222.                     }
    223.                 }
    224.             }
    225.             return $result;
    226.         }
    227.         else
    228.         {
    229.             return false;
    230.         }
    231.     }
    232.     // Report [END]
    233.    
    234.     /**
    235.     * Fetch current row
    236.     */
    237.     function sql_fetchrow ($result, $result_type = MYSQL_ASSOC)
    238.     {
    239.         return is_resource($result) ? mysql_fetch_array($result, $result_type) : false;
    240.     }
    241.  
    242.     /**
    243.     * Alias of sql_fetchrow()
    244.     */
    245.     function fetch_next ($result, $result_type = MYSQL_ASSOC)
    246.     {
    247.         return $this->sql_fetchrow($result, $result_type);
    248.     }
    249.  
    250.     /**
    251.     * Fetch row WRAPPER (with error handling)
    252.     */
    253.     function fetch_row ($query, $type = DEFAULT_QUERY_TYPE)
    254.     {
    255.         if (!$result = $this->sql_query($query, $type))
    256.         {
    257.             $this->trigger_error();
    258.         }
    259.  
    260.         return $this->sql_fetchrow($result);
    261.     }
    262.  
    263.     /**
    264.     * Fetch all rows
    265.     */
    266.     function sql_fetchrowset ($result, $result_type = MYSQL_ASSOC)
    267.     {
    268.         $rowset = array();
    269.  
    270.         while ($row = mysql_fetch_array($result, $result_type))
    271.         {
    272.             $rowset[] = $row;
    273.         }
    274.  
    275.         return $rowset;
    276.     }
    277.  
    278.     /**
    279.     * Fetch all rows WRAPPER (with error handling)
    280.     */
    281.     function fetch_rowset ($query, $type = DEFAULT_QUERY_TYPE)
    282.     {
    283.         if (!$result = $this->sql_query($query, $type))
    284.         {
    285.             $this->trigger_error();
    286.         }
    287.  
    288.         return $this->sql_fetchrowset($result);
    289.     }
    290.  
    291.     /**
    292.     * Get last inserted id after insert statement
    293.     */
    294.     function sql_nextid ()
    295.     {
    296.         return mysql_insert_id($this->link);
    297.     }
    298.  
    299.     /**
    300.     * Free sql result
    301.     */
    302.     function sql_freeresult ($result = false)
    303.     {
    304.         if ($result OR $result = $this->result)
    305.         {
    306.             $return_value = is_resource($result) ? mysql_free_result($result) : false;
    307.         }
    308.  
    309.         $this->result = null;
    310.     }
    311.  
    312.     /**
    313.     * Escape data used in sql query
    314.     */
    315.     function escape ($v, $check_type = false, $dont_escape = false)
    316.     {
    317.         if ($dont_escape) return $v;
    318.         if (!$check_type) return $this->escape_string($v);
    319.  
    320.         switch (true)
    321.         {
    322.             case is_string ($v): return "'". $this->escape_string($v) ."'";
    323.             case is_int    ($v): return "$v";
    324.             case is_bool   ($v): return ($v) ? '1' : '0';
    325.             case is_float  ($v): return "'$v'";
    326.             case is_null   ($v): return 'NULL';
    327.         }
    328.         // if $v has unsuitable type
    329.         $this->trigger_error(__FUNCTION__ .' - wrong params');
    330.     }
    331.  
    332.     /**
    333.     * Escape string
    334.     */
    335.     function escape_string ($str)
    336.     {
    337.         if (!is_resource($this->link))
    338.         {
    339.             $this->init();
    340.         }
    341.  
    342.         return mysql_real_escape_string($str);
    343.     }
    344.  
    345.     /**
    346.     * Build SQL statement from array (based on same method from phpBB3, idea from Ikonboard)
    347.     *
    348.     * Possible $query_type values: INSERT, INSERT_SELECT, MULTI_INSERT, UPDATE, SELECT
    349.     */
    350.     function build_array ($query_type, $input_ary, $data_already_escaped = false, $check_data_type_in_escape = true)
    351.     {
    352.         $fields = $values = $ary = $query = array();
    353.         $dont_escape = $data_already_escaped;
    354.         $check_type = $check_data_type_in_escape;
    355.  
    356.         if (empty($input_ary) || !is_array($input_ary))
    357.         {
    358.             $this->trigger_error(__FUNCTION__ .' - wrong params: $input_ary');
    359.         }
    360.  
    361.         if ($query_type == 'INSERT')
    362.         {
    363.             foreach ($input_ary as $field => $val)
    364.             {
    365.                 $fields[] = $field;
    366.                 $values[] = $this->escape($val, $check_type, $dont_escape);
    367.             }
    368.             $fields = join(', ', $fields);
    369.             $values = join(', ', $values);
    370.             $query = "($fields)\nVALUES\n($values)";
    371.         }
    372.         else if ($query_type == 'INSERT_SELECT')
    373.         {
    374.             foreach ($input_ary as $field => $val)
    375.             {
    376.                 $fields[] = $field;
    377.                 $values[] = $this->escape($val, $check_type, $dont_escape);
    378.             }
    379.             $fields = join(', ', $fields);
    380.             $values = join(', ', $values);
    381.             $query = "($fields)\nSELECT\n$values";
    382.         }
    383.         else if ($query_type == 'MULTI_INSERT')
    384.         {
    385.             foreach ($input_ary as $id => $sql_ary)
    386.             {
    387.                 foreach ($sql_ary as $field => $val)
    388.                 {
    389.                     $values[] = $this->escape($val, $check_type, $dont_escape);
    390.                 }
    391.                 $ary[] = '('. join(', ', $values) .')';
    392.                 $values = array();
    393.             }
    394.             $fields = join(', ', array_keys($input_ary[0]));
    395.             $values = join(",\n", $ary);
    396.             $query = "($fields)\nVALUES\n$values";
    397.         }
    398.         else if ($query_type == 'SELECT' || $query_type == 'UPDATE')
    399.         {
    400.             foreach ($input_ary as $field => $val)
    401.             {
    402.                 $ary[] = "$field = ". $this->escape($val, $check_type, $dont_escape);
    403.             }
    404.             $glue = ($query_type == 'SELECT') ? "\nAND " : ",\n";
    405.             $query = join($glue, $ary);
    406.         }
    407.  
    408.         if (!$query)
    409.         {
    410.             bb_die('<pre><b>'. __FUNCTION__ ."</b>: Wrong params for <b>$query_type</b> query type\n\n\$input_ary:\n\n". htmlCHR(print_r($input_ary, true)) .'</pre>');
    411.         }
    412.  
    413.         return "\n". $query ."\n";
    414.     }
    415.  
    416.     function get_empty_sql_array ()
    417.     {
    418.         return array(
    419.             'SELECT'         => array(),
    420.             'select_options' => array(),
    421.             'FROM'           => array(),
    422.             'INNER JOIN'     => array(),
    423.             'LEFT JOIN'      => array(),
    424.             'WHERE'          => array(),
    425.             'GROUP BY'       => array(),
    426.             'HAVING'         => array(),
    427.             'ORDER BY'       => array(),
    428.             'LIMIT'          => array(),
    429.         );
    430.     }
    431.  
    432.     function build_sql ($sql_ary)
    433.     {
    434.         $sql = '';
    435.         array_deep($sql_ary, 'array_unique', false, true);
    436.  
    437.         foreach ($sql_ary as $clause => $ary)
    438.         {
    439.             switch ($clause)
    440.             {
    441.             case 'SELECT':
    442.                 $sql .= ($ary) ? ' SELECT '. join(' ', $sql_ary['select_options']) .' '. join(', ', $ary) : '';
    443.                 break;
    444.             case 'FROM':
    445.                 $sql .= ($ary) ? ' FROM '. join(', ', $ary) : '';
    446.                 break;
    447.             case 'INNER JOIN':
    448.                 $sql .= ($ary) ? ' INNER JOIN '. join(' INNER JOIN ', $ary) : '';
    449.                 break;
    450.             case 'LEFT JOIN':
    451.                 $sql .= ($ary) ? ' LEFT JOIN '. join(' LEFT JOIN ', $ary) : '';
    452.                 break;
    453.             case 'WHERE':
    454.                 $sql .= ($ary) ? ' WHERE '. join(' AND ', $ary) : '';
    455.                 break;
    456.             case 'GROUP BY':
    457.                 $sql .= ($ary) ? ' GROUP BY '. join(', ', $ary) : '';
    458.                 break;
    459.             case 'HAVING':
    460.                 $sql .= ($ary) ? ' HAVING '. join(' AND ', $ary) : '';
    461.                 break;
    462.             case 'ORDER BY':
    463.                 $sql .= ($ary) ? ' ORDER BY '. join(', ', $ary) : '';
    464.                 break;
    465.             case 'LIMIT':
    466.                 $sql .= ($ary) ? ' LIMIT '. join(', ', $ary) : '';
    467.                 break;
    468.             }
    469.         }
    470.  
    471.         return trim($sql);
    472.     }
    473.  
    474.     /**
    475.     * Return sql error array
    476.     */
    477.     function sql_error ()
    478.     {
    479.         $return_ary = array(
    480.             'code'    => '',
    481.             'message' => 'not connected',
    482.         );
    483.  
    484.         if (is_resource($this->link))
    485.         {
    486.             $return_ary = array(
    487.                 'code'    => mysql_errno($this->link),
    488.                 'message' => mysql_error($this->link),
    489.             );
    490.         }
    491.  
    492.         return $return_ary;
    493.     }
    494.  
    495.     /**
    496.     * Close sql connection
    497.     */
    498.     function sql_close ()
    499.     {
    500.         if (is_resource($this->link))
    501.         {
    502.             $this->unlock();
    503.  
    504.             if (!empty($this->locks))
    505.             {
    506.                 foreach ($this->locks as $name => $void)
    507.                 {
    508.                     $this->release_lock($name);
    509.                 }
    510.             }
    511.  
    512.             $this->exec_shutdown_queries();
    513.  
    514.             mysql_close($this->link);
    515.         }
    516.  
    517.         $this->link = $this->selected_db = null;
    518.     }
    519.  
    520.     /**
    521.     * Add shutdown query
    522.     */
    523.     function add_shutdown_query ($sql)
    524.     {
    525.         $this->shutdown['__sql'][] = $sql;
    526.     }
    527.  
    528.     /**
    529.     * Exec shutdown queries
    530.     */
    531.     function exec_shutdown_queries ()
    532.     {
    533.         if (empty($this->shutdown)) return;
    534.  
    535.         // post_html
    536.         if (!empty($this->shutdown['post_html']))
    537.         {
    538.             $post_html_sql = $this->build_array('MULTI_INSERT', $this->shutdown['post_html']);
    539.             $this->query("REPLACE INTO ". POSTS_HTML_TABLE ." $post_html_sql");
    540.         }
    541.         // other
    542.         if (!empty($this->shutdown['__sql']))
    543.         {
    544.             foreach ($this->shutdown['__sql'] as $sql)
    545.             {
    546.                 $this->query($sql);
    547.             }
    548.         }
    549.     }
    550.  
    551.     /**
    552.     * Return the number of fields from a query
    553.     */
    554.     function sql_numfields ($result)
    555.     {
    556.         return (is_resource($result)) ? mysql_num_fields($result) : false;
    557.     }
    558.  
    559.     /**
    560.     * Return the name of the field index
    561.     */
    562.     function sql_fieldname ($offset, $result)
    563.     {
    564.         return (is_resource($result)) ? mysql_field_name($result, $offset) : false;
    565.     }
    566.  
    567.     /**
    568.     * Return the type of the field
    569.     */
    570.     function sql_fieldtype ($offset, $result = false)
    571.     {
    572.         return (is_resource($result)) ? mysql_field_type($result, $offset) : false;
    573.     }
    574.  
    575.     /**
    576.     * Lock tables
    577.     */
    578.     function lock ($tables, $lock_type = 'WRITE')
    579.     {
    580.         if ($this->pconnect)
    581.         {
    582. #           return true;
    583.         }
    584.  
    585.         $tables_sql = array();
    586.  
    587.         foreach ((array) $tables as $table_name)
    588.         {
    589.             $tables_sql[] = "$table_name $lock_type";
    590.         }
    591.         if ($tables_sql = join(', ', $tables_sql))
    592.         {
    593.             $this->locked = $this->sql_query("LOCK TABLES $tables_sql");
    594.         }
    595.  
    596.         return $this->locked;
    597.     }
    598.  
    599.     /**
    600.     * Unlock tables
    601.     */
    602.     function unlock ()
    603.     {
    604.         if ($this->locked && $this->sql_query("UNLOCK TABLES"))
    605.         {
    606.             $this->locked = false;
    607.         }
    608.  
    609.         return !$this->locked;
    610.     }
    611.  
    612.     /**
    613.     * Obtain user level lock
    614.     */
    615.     function get_lock ($name, $timeout = 0)
    616.     {
    617.         $lock_name = $this->get_lock_name($name);
    618.         $timeout   = (int) $timeout;
    619.         $row = $this->fetch_row("SELECT GET_LOCK('$lock_name', $timeout) AS lock_result");
    620.  
    621.         if ($row['lock_result'])
    622.         {
    623.             $this->locks[$name] = true;
    624.         }
    625.  
    626.         return $row['lock_result'];
    627.     }
    628.  
    629.     /**
    630.     * Obtain user level lock status
    631.     */
    632.     function release_lock ($name)
    633.     {
    634.         $lock_name = $this->get_lock_name($name);
    635.         $row = $this->fetch_row("SELECT RELEASE_LOCK('$lock_name') AS lock_result");
    636.  
    637.         if ($row['lock_result'])
    638.         {
    639.             unset($this->locks[$name]);
    640.         }
    641.  
    642.         return $row['lock_result'];
    643.     }
    644.  
    645.     /**
    646.     * Release user level lock
    647.     */
    648.     function is_free_lock ($name)
    649.     {
    650.         $lock_name = $this->get_lock_name($name);
    651.         $row = $this->fetch_row("SELECT IS_FREE_LOCK('$lock_name') AS lock_result");
    652.         return $row['lock_result'];
    653.     }
    654.  
    655.     /**
    656.     * Make per db unique lock name
    657.     */
    658.     function get_lock_name ($name)
    659.     {
    660.         if (!$this->selected_db)
    661.         {
    662.             $this->init();
    663.         }
    664.  
    665.         return "{$this->selected_db}_{$name}";
    666.     }
    667.  
    668.     /**
    669.     * Get info about last query
    670.     */
    671.     function query_info ()
    672.     {
    673.         $info = array();
    674.  
    675.         if ($num = $this->sql_numrows($this->result))
    676.         {
    677.             $info[] = "$num rows";
    678.         }
    679.  
    680.         if (is_resource($this->link) AND $ext = mysql_info($this->link))
    681.         {
    682.             $info[] = "$ext";
    683.         }
    684.         else if (!$num && ($aff = $this->sql_affectedrows($this->result) AND $aff != -1))
    685.         {
    686.             $info[] = "$aff rows";
    687.         }
    688.  
    689.         return str_compact(join(', ', $info));
    690.     }
    691.  
    692.     /**
    693.     * Get server version
    694.     */
    695.     function server_version ()
    696.     {
    697.         preg_match('#^(\d+\.\d+\.\d+).*#', mysql_get_server_info(), $m);
    698.         return $m[1];
    699.     }
    700.  
    701.     /**
    702.     * Set slow query marker for xx seconds
    703.     * This will disable counting other queries as "slow" during this time
    704.     */
    705.     function expect_slow_query ($ignoring_time = 60, $new_priority = 10)
    706.     {
    707.         global $bb_cache;
    708.  
    709.         if ($old_priority = $bb_cache->get('dont_log_slow_query'))
    710.         {
    711.             if ($old_priority > $new_priority)
    712.             {
    713.                 return;
    714.             }
    715.         }
    716.  
    717.         @define('IN_FIRST_SLOW_QUERY', true);
    718.         $bb_cache->set('dont_log_slow_query', $new_priority, $ignoring_time);
    719.     }
    720.  
    721.     /**
    722.     * Store debug info
    723.     */
    724.     function debug ($mode)
    725.     {
    726.         if (!SQL_DEBUG) return;
    727.  
    728.         $id  =& $this->dbg_id;
    729.         $dbg =& $this->dbg[$id];
    730.  
    731.         if ($mode == 'start')
    732.         {
    733.             if (SQL_CALC_QUERY_TIME || DBG_LOG || SQL_LOG_SLOW_QUERIES)
    734.             {
    735.                 $this->sql_starttime = utime();
    736.             }
    737.             if ($this->dbg_enabled)
    738.             {
    739.                 $dbg['sql']  = $this->cur_query;
    740.                 $dbg['src']  = $this->debug_find_source();
    741.                 $dbg['file'] = $this->debug_find_source('file');
    742.                 $dbg['line'] = $this->debug_find_source('line');
    743.                 $dbg['time'] = '';
    744.                 $dbg['info'] = '';
    745.                 $dbg['mem_before'] = (MEM_USAGE) ? memory_get_usage() : null;
    746.             }
    747.             if ($this->do_explain)
    748.             {
    749.                 $this->explain('start');
    750.             }
    751.         }
    752.         else if ($mode == 'stop')
    753.         {
    754.             if (SQL_CALC_QUERY_TIME || DBG_LOG || SQL_LOG_SLOW_QUERIES)
    755.             {
    756.                 $this->cur_query_time = utime() - $this->sql_starttime;
    757.                 $this->sql_timetotal += $this->cur_query_time;
    758.  
    759.                 if (SQL_LOG_SLOW_QUERIES && $this->cur_query_time > SQL_SLOW_QUERY_TIME)
    760.                 {
    761.                     $this->log_slow_query();
    762.                 }
    763.             }
    764.             if ($this->dbg_enabled)
    765.             {
    766.                 $dbg['time'] = utime() - $this->sql_starttime;
    767.                 $dbg['info'] = $this->query_info();
    768.                 $dbg['mem_after'] = (MEM_USAGE) ? memory_get_usage() : null;
    769.                 $id++;
    770.             }
    771.             if ($this->do_explain)
    772.             {
    773.                 $this->explain('stop');
    774.             }
    775.             if ($this->log_counter)
    776.             {
    777.                 $this->log_query($this->log_file, 4);
    778.                 $this->log_counter--;
    779.             }
    780.         }
    781.     }
    782.  
    783.     /**
    784.     * Trigger error
    785.     */
    786.     function trigger_error ($msg = 'DB Error')
    787.     {
    788.         if (error_reporting())
    789.         {
    790.             if (DEBUG === true)
    791.             {
    792.                 $err = $this->sql_error();
    793.                 $msg .= "\n". trim(sprintf('#%06d %s', $err['code'], $err['message']));
    794.             }
    795.             else
    796.             {
    797.                 $msg .= " [". $this->debug_find_source() ."]";
    798.             }
    799.  
    800.             trigger_error($msg, E_USER_ERROR);
    801.         }
    802.     }
    803.  
    804.     /**
    805.     * Find caller source
    806.     */
    807.     function debug_find_source ($mode = '')
    808.     {
    809.         foreach (debug_backtrace() as $trace)
    810.         {
    811.             if (!empty($trace['file']) &&  $trace['file'] !== __FILE__)
    812.             {
    813.                 switch ($mode)
    814.                 {
    815.                     case 'file': return $trace['file'];
    816.                     case 'line': return $trace['line'];
    817.                     default: return hide_bb_path($trace['file']) .'('. $trace['line'] .')';
    818.                 }
    819.             }
    820.         }
    821.         return '';
    822.     }
    823.  
    824.     /**
    825.     * Prepare for logging
    826.     */
    827.     function log_next_query ($queries_count = 1, $log_file = 'sql_queries')
    828.     {
    829.         $this->log_file = $log_file;
    830.         $this->log_counter = $queries_count;
    831.     }
    832.  
    833.     /**
    834.     * Log query
    835.     */
    836.     function log_query ($log_file = 'sql_queries', $time_precision = 0)
    837.     {
    838.         $msg = array();
    839.         $msg[] = date('m-d', $this->sql_starttime);
    840.         $msg[] = date('H:i:s', $this->sql_starttime);
    841.         $msg[] = sprintf('%-'.($time_precision+3).'s', sprintf("%.{$time_precision}f", $this->cur_query_time));
    842.         $msg[] = (LOADAVG) ? sprintf('%-4s', round(get_loadavg(), 1)) : '-';
    843.         $msg[] = sprintf('%05d', getmypid());
    844.         $msg[] = str_compact($this->cur_query);
    845.         $msg = join(LOG_SEPR, $msg);
    846.         $msg .= ($info = $this->query_info()) ? ' # '. $info : '';
    847.         $msg .= ' # '. $this->debug_find_source();
    848.         bb_log($msg . LOG_LF, $log_file);
    849.     }
    850.  
    851.     /**
    852.     * Log slow query
    853.     */
    854.     function log_slow_query ($log_file = 'sql_slow_bb')
    855.     {
    856.         if (!defined('IN_FIRST_SLOW_QUERY') && $GLOBALS['bb_cache']->get('dont_log_slow_query'))
    857.         {
    858.             return;
    859.         }
    860.         $this->log_query($log_file);
    861.     }
    862.  
    863.     /**
    864.     * Log error
    865.     */
    866.     function log_error ()
    867.     {
    868.         if (!SQL_LOG_ERRORS) return;
    869.  
    870.         $msg = array();
    871.         $err = $this->sql_error();
    872.         $msg[] = str_compact(sprintf('#%06d %s', $err['code'], $err['message']));
    873.         $msg[] = '';
    874.         $msg[] = str_compact($this->cur_query);
    875.         $msg[] = '';
    876.         $msg[] = 'Source  : '. $this->debug_find_source();
    877.         $msg[] = 'IP      : '. @$_SERVER['REMOTE_ADDR'];
    878.         $msg[] = 'Date    : '. date('Y-m-d H:i:s');
    879.         $msg[] = 'Agent   : '. @$_SERVER['HTTP_USER_AGENT'];
    880.         $msg[] = 'Req_URI : '. @$_SERVER['REQUEST_URI'];
    881.         $msg[] = 'Referer : '. @$_SERVER['HTTP_REFERER'];
    882.         $msg[] = 'Method  : '. @$_SERVER['REQUEST_METHOD'];
    883.         $msg[] = 'PID     : '. sprintf('%05d', getmypid());
    884.         $msg[] = 'Request : '. trim(print_r($_REQUEST, true)) . str_repeat('_', 78) . LOG_LF;
    885.         $msg[] = '';
    886.         bb_log($msg, 'sql_error_bb');
    887.     }
    888.  
    889.     /**
    890.     * Explain queries (based on code from phpBB3)
    891.     */
    892.     function explain ($mode, $html_table = '', $row = '')
    893.     {
    894.         $query = str_compact($this->cur_query);
    895.  
    896.         switch ($mode)
    897.         {
    898.         case 'start':
    899.             $this->explain_hold = '';
    900.             // TODO: добавить поддержку многотабличных запросов
    901.             if (preg_match('#UPDATE ([a-z0-9_]+).*?WHERE(.*)/#', $query, $m))
    902.             {
    903.                 $query = "SELECT * FROM $m[1] WHERE $m[2]";
    904.             }
    905.             else if (preg_match('#DELETE FROM ([a-z0-9_]+).*?WHERE(.*)#s', $query, $m))
    906.             {
    907.                 $query = "SELECT * FROM $m[1] WHERE $m[2]";
    908.             }
    909.  
    910.             if (preg_match('#^SELECT#', $query))
    911.             {
    912.                 $html_table = false;
    913.  
    914.                 if ($result = @mysql_query("EXPLAIN $query", $this->link))
    915.                 {
    916.                     while ($row = @mysql_fetch_assoc($result))
    917.                     {
    918.                         $html_table = $this->explain('add_explain_row', $html_table, $row);
    919.                     }
    920.                 }
    921.                 if ($html_table)
    922.                 {
    923.                     $this->explain_hold .= '</table>';
    924.                 }
    925.             }
    926.             break;
    927.  
    928.         case 'stop':
    929.             if (!$this->explain_hold) break;
    930.  
    931.             $id   = $this->dbg_id-1;
    932.             $dbg  = $this->dbg[$id];
    933.             $file = addslashes($dbg['file']);
    934.             $line = $dbg['line'];
    935.             $edit = (DEBUG === true) ? "OpenInEditor('$file', $line);" : '';
    936.  
    937.             $this->explain_out .= '
    938.                 <table width="98%" cellpadding="0" cellspacing="0" class="bodyline row2 bCenter" style="border-bottom: 0px;">
    939.                 <tr>
    940.                     <th style="height: 22px; cursor: pointer;" align="left" title="Open in editor (double click)" ondblclick="'. $edit .'">&nbsp;'. $dbg['src'] .'&nbsp; ['. sprintf('%.4f', $dbg['time']) .' s]&nbsp; <i>'. $dbg['info'] .'</i></th>
    941.                     <th style="height: 22px; cursor: pointer;" align="right" title="Copy to clipboard" onclick="if (ie_copyTextToClipboard($p(\'expl_'. $id .'\'))) alert(\'SQL copied to clipboard\');">Query #'. ($this->num_queries+1) .'&nbsp;</th>
    942.                 </tr>
    943.                 <tr><td colspan="2">'. $this->explain_hold .'</td></tr>
    944.                 </table>
    945.                 <div class="sqlLog"><div id="expl_'. $id .'" class="sqlLogRow sqlExplain" style="padding: 0px;">'. sql_log_query_short($dbg['sql']) .'&nbsp;&nbsp;'. (UA_IE ? '<br /><br />' : '') .'</div></div>
    946.                 <br />';
    947.             break;
    948.  
    949.         case 'add_explain_row':
    950.             if (!$html_table && $row)
    951.             {
    952.                 $html_table = true;
    953.                 $this->explain_hold .= '<table width="100%" cellpadding="3" cellspacing="1" class="bodyline" style="border-width: 0px;"><tr>';
    954.                 foreach (array_keys($row) as $val)
    955.                 {
    956.                     $this->explain_hold .= '<td class="row3 gensmall" align="center"><b>'. $val .'</b></td>';
    957.                 }
    958.                 $this->explain_hold .= '</tr>';
    959.             }
    960.             $this->explain_hold .= '<tr>';
    961.             foreach (array_values($row) as $i => $val)
    962.             {
    963.                 $class = !($i % 2) ? 'row1' : 'row2';
    964.                 $this->explain_hold .= '<td class="'. $class .' gen">'. str_replace(array("{$this->selected_db}.", ',', ';'), array('', ', ', ';<br />'), $val) .'</td>';
    965.             }
    966.             $this->explain_hold .= '</tr>';
    967.  
    968.             return $html_table;
    969.  
    970.             break;
    971.  
    972.         case 'display':
    973.             echo '<a name="explain"></a><div class="genmed">'. $this->explain_out .'</div>';
    974.             break;
    975.         }
    976.     }
    977. }
    978.  
    979. function sql_log_query_short ($sql, $max_len = 6000)
    980. {
    981.     $max_len = max($max_len, 1000);
    982.     $sql = str_compact($sql);
    983.  
    984.     if (empty($_COOKIE['sql_log_full']))
    985.     {
    986.         if (strlen($sql) > $max_len)
    987.         {
    988.             $sql = substr($sql, 0, $max_len-200) .' [...cut...] '. substr($sql, -180);
    989.         }
    990.     }
    991.  
    992.     return htmlCHR($sql);
    993. }
    994.  
    995.  
     
  10. Gromo

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

    С нами с:
    24 май 2010
    Сообщения:
    2.786
    Симпатии:
    2
    Адрес:
    Ташкент
    aceman17
    довольно странно. конекретно с данной ошибкой не встречался,
    но по идее функция trigger_error - это пхп-шная функция начиная с версии 4.1, так что должно всё работать.
    с другой стороны складывается впечатление, что сбоит сама функция где-то внутри, генерируя фатал эррор.

    сама ошибка происходит при работе с базой данных - может таблица не создана, или запрос подаёшь не так.
    вместо trigger_error($msg, E_USER_ERROR); поставь die($msg); чтобы увидеть сгенерированную ошибку.

    это конечно не избавит от текущей ошибки, однако поможет решить другую ошибку, генерирующую данную.
     
  11. aceman17

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

    С нами с:
    3 май 2011
    Сообщения:
    23
    Симпатии:
    0
    ошибка ушла появилась эта [includes/functions_group.php(24)]
     
  12. aceman17

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

    С нами с:
    3 май 2011
    Сообщения:
    23
    Симпатии:
    0
    как с ней быть [includes/functions_group.php(24)]
     
  13. Gromo

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

    С нами с:
    24 май 2010
    Сообщения:
    2.786
    Симпатии:
    2
    Адрес:
    Ташкент
    aceman17
    это ошибки из лога? тут нет описания ошибки, ни того где и из-за чего она возникла.
    можно только предположить, что возникает она на 24 строчке файла includes/functions_group.php
     
  14. aceman17

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

    С нами с:
    3 май 2011
    Сообщения:
    23
    Симпатии:
    0
    возникает когда обновляю права пользователей или удаляю материал
     
  15. aceman17

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

    С нами с:
    3 май 2011
    Сообщения:
    23
    Симпатии:
    0
    PHP:
    1. <?php
    2.  
    3. if (!defined('BB_ROOT')) die(basename(__FILE__));
    4.  
    5. function update_user_level ($user_id)
    6. {
    7.     global $db, $datastore;
    8.  
    9.     if (is_array($user_id))
    10.     {
    11.         $user_id = join(',', $user_id);
    12.     }
    13.     $user_groups_in = ($user_id !== 'all') ? "AND ug.user_id IN($user_id)" : '';
    14.     $users_in       = ($user_id !== 'all') ? "AND  u.user_id IN($user_id)" : '';
    15.  
    16.     $tmp_table = 'tmp_levels';
    17.  
    18.     $db->query("
    19.         CREATE TEMPORARY TABLE $tmp_table (
    20.             user_id MEDIUMINT NOT NULL DEFAULT '0',
    21.             user_level TINYINT NOT NULL DEFAULT '0',
    22.             PRIMARY KEY (user_id)
    23.         ) ENGINE = MEMORY
    24.     ");
    25.  
    26.     $db->query("
    27.         REPLACE INTO $tmp_table (user_id, user_level)
    28.             SELECT u.user_id, ". USER ."
    29.             FROM ". USERS_TABLE ." u
    30.             WHERE user_level NOT IN(". USER .",". ADMIN .")
    31.                 $users_in
    32.         UNION
    33.             SELECT DISTINCT ug.user_id, ". GROUP_MEMBER ."
    34.             FROM ". GROUPS_TABLE ." g, ". USER_GROUP_TABLE ." ug
    35.             WHERE g.group_single_user = 0
    36.                 AND ug.group_id = g.group_id
    37.                 AND ug.user_pending = 0
    38.                     $user_groups_in
    39.         UNION
    40.             SELECT DISTINCT ug.user_id, ". MOD ."
    41.             FROM ". AUTH_ACCESS_TABLE ." aa, ". USER_GROUP_TABLE ." ug
    42.             WHERE aa.forum_perm & ". BF_AUTH_MOD ."
    43.                 AND ug.group_id = aa.group_id
    44.                 AND ug.user_pending = 0
    45.                     $user_groups_in
    46.     ");
    47.  
    48.     $db->query("
    49.         UPDATE ". USERS_TABLE ." u, $tmp_table lev SET
    50.             u.user_level = lev.user_level
    51.         WHERE lev.user_id = u.user_id
    52.             AND u.user_level NOT IN(". ADMIN .")
    53.                 $users_in
    54.     ");
    55.  
    56.     $db->query("DROP TEMPORARY TABLE $tmp_table");
    57.  
    58.     update_user_permissions($user_id);
    59.     delete_orphan_usergroups();
    60.     $datastore->update('moderators');
    61. }
    62.  
    63. function delete_group ($group_id)
    64. {
    65.     global $db;
    66.  
    67.     $group_id = (int) $group_id;
    68.  
    69.     $db->query("
    70.         DELETE ug, g, aa
    71.         FROM ". USER_GROUP_TABLE ." ug
    72.         LEFT JOIN ". GROUPS_TABLE ." g ON(g.group_id = $group_id)
    73.         LEFT JOIN ". AUTH_ACCESS_TABLE ." aa ON(aa.group_id = $group_id)
    74.         WHERE ug.group_id = $group_id
    75.     ");
    76.  
    77.     update_user_level('all');
    78. }
    79.  
    80. function add_user_into_group ($group_id, $user_id, $user_pending = 0)
    81. {
    82.     $time=time();
    83.     $args = $GLOBALS['db']->build_array('INSERT', array(
    84.         'group_id'     => (int) $group_id,
    85.         'user_id'      => (int) $user_id,
    86.         'user_pending' => (int) $user_pending,
    87.         'in_time'      => (int) $time,
    88.     ));
    89.     $GLOBALS['db']->query("REPLACE INTO ". USER_GROUP_TABLE . $args);
    90.  
    91.     if (!$user_pending)
    92.     {
    93.         update_user_level($user_id);
    94.     }
    95. }
    96.  
    97. function delete_user_group ($group_id, $user_id)
    98. {
    99.     $GLOBALS['db']->query("
    100.         DELETE FROM ". USER_GROUP_TABLE ."
    101.         WHERE user_id = ". (int) $user_id ."
    102.             AND group_id = ". (int) $group_id ."
    103.     ");
    104.  
    105.     update_user_level($user_id);
    106. }
    107.  
    108. function create_user_group ($user_id)
    109. {
    110.     global $db;
    111.  
    112.     $db->query("INSERT INTO ". GROUPS_TABLE ." (group_single_user) VALUES (1)");
    113.  
    114.     $group_id = (int) $db->sql_nextid();
    115.     $user_id  = (int) $user_id;
    116.  
    117.     $db->query("INSERT INTO ". USER_GROUP_TABLE ." (user_id, group_id) VALUES ($user_id, $group_id)");
    118.  
    119.     return $group_id;
    120. }
    121.  
    122. function get_group_data ($group_id)
    123. {
    124.     global $db;
    125.  
    126.     if ($group_id === 'all')
    127.     {
    128.         $sql = "SELECT g.*, u.username AS moderator_name, aa.group_id AS auth_mod
    129.             FROM ". GROUPS_TABLE ." g
    130.             LEFT JOIN ". USERS_TABLE ." u ON(g.group_moderator = u.user_id)
    131.             LEFT JOIN ". AUTH_ACCESS_TABLE ." aa ON(aa.group_id = g.group_id AND aa.forum_perm & ". BF_AUTH_MOD .")
    132.             WHERE g.group_single_user = 0
    133.             GROUP BY g.group_id
    134.             ORDER BY g.group_name";
    135.     }
    136.     else
    137.     {
    138.         $sql = "SELECT g.*, u.username AS moderator_name, aa.group_id AS auth_mod
    139.             FROM ". GROUPS_TABLE ." g
    140.             LEFT JOIN ". USERS_TABLE ." u ON(g.group_moderator = u.user_id)
    141.             LEFT JOIN ". AUTH_ACCESS_TABLE ." aa ON(aa.group_id = g.group_id AND aa.forum_perm & ". BF_AUTH_MOD .")
    142.             WHERE g.group_id = ". (int) $group_id ."
    143.                 AND g.group_single_user = 0
    144.             LIMIT 1";
    145.     }
    146.     $method = ($group_id === 'all') ? 'fetch_rowset' : 'fetch_row';
    147.     return $db->$method($sql);
    148. }
    149.  
    150. function delete_permissions ($group_id = null, $user_id = null, $cat_id = null)
    151. {
    152.     global $db;
    153.  
    154.     $group_id = get_id_csv($group_id);
    155.     $user_id  = get_id_csv($user_id);
    156.     $cat_id   = get_id_csv($cat_id);
    157.  
    158.     $forums_join_sql = ($cat_id) ? "
    159.         INNER JOIN ". FORUMS_TABLE ." f ON(a.forum_id = f.forum_id AND f.cat_id IN($cat_id))
    160.     " : '';
    161.  
    162.     if ($group_id)
    163.     {
    164.         $db->query("DELETE a FROM ". AUTH_ACCESS_TABLE ." a $forums_join_sql WHERE a.group_id IN($group_id)");
    165.     }
    166.     if ($user_id)
    167.     {
    168.         $db->query("DELETE a FROM ". AUTH_ACCESS_SNAP_TABLE ." a $forums_join_sql WHERE a.user_id IN($user_id)");
    169.     }
    170. }
    171.  
    172. function store_permissions ($group_id, $auth_ary)
    173. {
    174.     global $db;
    175.  
    176.     if (empty($auth_ary) || !is_array($auth_ary)) return;
    177.  
    178.     $values = array();
    179.  
    180.     foreach ($auth_ary as $forum_id => $permission)
    181.     {
    182.         $values[] = array(
    183.             'group_id'   => (int) $group_id,
    184.             'forum_id'   => (int) $forum_id,
    185.             'forum_perm' => (int) $permission,
    186.         );
    187.     }
    188.     $values = $db->build_array('MULTI_INSERT', $values);
    189.  
    190.     $db->query("INSERT INTO ". AUTH_ACCESS_TABLE . $values);
    191. }
    192.  
    193. function update_user_permissions ($user_id = 'all')
    194. {
    195.     global $db;
    196.  
    197.     if (is_array($user_id))
    198.     {
    199.         $user_id = join(',', $user_id);
    200.     }
    201.     $delete_in = ($user_id !== 'all') ? " WHERE user_id IN($user_id)" : '';
    202.     $users_in  = ($user_id !== 'all') ? "AND ug.user_id IN($user_id)" : '';
    203.  
    204.     $db->query("DELETE FROM ". AUTH_ACCESS_SNAP_TABLE . $delete_in);
    205.  
    206.     $db->query("
    207.         INSERT INTO ". AUTH_ACCESS_SNAP_TABLE ."
    208.             (user_id, forum_id, forum_perm)
    209.         SELECT
    210.             ug.user_id, aa.forum_id, BIT_OR(aa.forum_perm)
    211.         FROM
    212.             ". USER_GROUP_TABLE  ." ug,
    213.             ". GROUPS_TABLE      ." g,
    214.             ". AUTH_ACCESS_TABLE ." aa
    215.         WHERE
    216.                 ug.user_pending = 0
    217.                 $users_in
    218.             AND g.group_id = ug.group_id
    219.             AND aa.group_id = g.group_id
    220.         GROUP BY
    221.             ug.user_id, aa.forum_id
    222.     ");
    223. }
    224.  
    225. function delete_orphan_usergroups ()
    226. {
    227.     global $db;
    228.  
    229.     // GROUP_SINGLE_USER without AUTH_ACCESS
    230.     $db->query("
    231.         DELETE g
    232.         FROM ". GROUPS_TABLE ." g
    233.         LEFT JOIN ". AUTH_ACCESS_TABLE ." aa USING(group_id)
    234.         WHERE g.group_single_user = 1
    235.             AND aa.group_id IS NULL
    236.     ");
    237.  
    238.     // orphan USER_GROUP (against GROUP table)
    239.     $db->query("
    240.         DELETE ug
    241.         FROM ". USER_GROUP_TABLE ." ug
    242.         LEFT JOIN ". GROUPS_TABLE ." g USING(group_id)
    243.         WHERE g.group_id IS NULL
    244.     ");
    245. }
    246.  
     
  16. aceman17

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

    С нами с:
    3 май 2011
    Сообщения:
    23
    Симпатии:
    0
    вот файл весь
     
  17. Gromo

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

    С нами с:
    24 май 2010
    Сообщения:
    2.786
    Симпатии:
    2
    Адрес:
    Ташкент
    aceman17
    я бы проверил первым делом через PMA создаётся ли вообще временная таблица в памяти.
    возможно, что у текущего пользователя не хватает прав на создание таблицы