|
From: FlorinCB <ory...@us...> - 2008-09-30 07:05:39
|
Update of /cvsroot/mxbb/core/includes/db In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv26368/includes/db Modified Files: dbal.php mysql.php Log Message: rewrite for php4 and php6 issues Index: mysql.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/db/mysql.php,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** mysql.php 19 Aug 2008 02:46:22 -0000 1.19 --- mysql.php 30 Sep 2008 07:04:36 -0000 1.20 *************** *** 52,56 **** $this->db_connect_id = ($this->persistency) ? @mysql_pconnect($this->server, $this->user, $sqlpassword, $new_link) : @mysql_connect($this->server, $this->user, $sqlpassword, $new_link); ! if ($this->db_connect_id && $this->dbname != '') { --- 52,56 ---- $this->db_connect_id = ($this->persistency) ? @mysql_pconnect($this->server, $this->user, $sqlpassword, $new_link) : @mysql_connect($this->server, $this->user, $sqlpassword, $new_link); ! if ($this->db_connect_id && $this->dbname != '') { *************** *** 59,63 **** // Determine what version we are using and if it natively supports UNICODE $this->mysql_version = mysql_get_server_info($this->db_connect_id); ! if (version_compare($this->mysql_version, '4.1.3', '>=')) { --- 59,63 ---- // Determine what version we are using and if it natively supports UNICODE $this->mysql_version = mysql_get_server_info($this->db_connect_id); ! if (version_compare($this->mysql_version, '4.1.3', '>=')) { *************** *** 100,105 **** } } ! ! return $this->sql_error(''); } --- 100,104 ---- } } ! return $this->sql_error(); } Index: dbal.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/db/dbal.php,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** dbal.php 16 Feb 2008 22:15:56 -0000 1.10 --- dbal.php 30 Sep 2008 07:04:35 -0000 1.11 *************** *** 34,41 **** var $html_hold = ''; var $sql_report = ''; ! var $cache_num_queries = 0; var $persistency = false; ! var $user = ''; var $server = ''; var $dbname = ''; --- 34,41 ---- var $html_hold = ''; var $sql_report = ''; ! var $mx_cache_num_queries = 0; var $persistency = false; ! var $mx_user = ''; var $server = ''; var $dbname = ''; *************** *** 83,87 **** * Doing some validation here. */ ! function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) { if (empty($query)) --- 83,87 ---- * Doing some validation here. */ ! function sql_query_limit($query, $total, $offset = 0, $mx_cache_ttl = 0) { if (empty($query)) *************** *** 94,98 **** $offset = ($offset < 0) ? 0 : $offset; ! return $this->_sql_query_limit($query, $total, $offset, $cache_ttl); } --- 94,98 ---- $offset = ($offset < 0) ? 0 : $offset; ! return $this->_sql_query_limit($query, $total, $offset, $mx_cache_ttl); } *************** *** 415,434 **** function sql_error($sql = '') { ! global $mx_user; ! $error = $this->_sql_error(); if (!$this->return_on_error) { ! $message = '<u>SQL ERROR</u> [ ' . SQL_LAYER . ' ]<br /><br />' . $error['message'] . ' [' . $error['code'] . ']'; // Show complete SQL error and path to administrators only ! if ($mx_user->is_admin) { // Print out a nice backtrace... ! //$backtrace = get_backtrace(); ! $message .= ($sql) ? '<br /><br /><u>SQL</u><br /><br />' . $sql : ''; ! //$message .= ($backtrace) ? '<br /><br /><u>BACKTRACE</u><br />' . $backtrace : ''; $message .= '<br />'; } --- 415,441 ---- function sql_error($sql = '') { ! global $mx_auth, $mx_user, $board_config; ! global $phpBB3; ! // Set var to retrieve errored status ! $this->sql_error_triggered = true; ! $this->sql_error_sql = $sql; ! ! $this->sql_error_returned = $this->_sql_error(); if (!$this->return_on_error) { ! $message = 'SQL ERROR [ ' . $this->sql_layer . ' ]<br /><br />' . $this->sql_error_returned['message'] . ' [' . $this->sql_error_returned['code'] . ']'; // Show complete SQL error and path to administrators only ! // Additionally show complete error on installation or if extended debug mode is enabled ! // The DEBUG_EXTRA constant is for development only! ! if ((isset($mx_auth) && $mx_auth->acl_get('a_')) || defined('IN_INSTALL') || defined('DEBUG_EXTRA')) { // Print out a nice backtrace... ! $backtrace = $phpBB3->get_backtrace(); ! $message .= ($sql) ? '<br /><br />SQL<br /><br />' . htmlspecialchars($sql) : ''; ! $message .= ($backtrace) ? '<br /><br />BACKTRACE<br />' . $backtrace : ''; $message .= '<br />'; } *************** *** 437,447 **** // If error occurs in initiating the session we need to use a pre-defined language string // This could happen if the connection could not be established for example (then we are not able to grab the default language) ! if (!isset($mx_user->_lang['An_error_occured'])) { ! $message .= '<br /><br />An sql error occurred while fetching this page. Please contact an administrator if this problem persist.'; } else { ! $message .= '<br /><br />' . $mx_user->_lang['An_error_occured']; } } --- 444,461 ---- // If error occurs in initiating the session we need to use a pre-defined language string // This could happen if the connection could not be established for example (then we are not able to grab the default language) ! if (!isset($mx_user->lang['SQL_ERROR_OCCURRED'])) { ! $message .= '<br /><br />An sql error occurred while fetching this page. Please contact an administrator if this problem persists.'; } else { ! if (!empty($board_config['board_contact'])) ! { ! $message .= '<br /><br />' . sprintf($mx_user->lang['SQL_ERROR_OCCURRED'], '<a href="mailto:' . htmlspecialchars($board_config['board_contact']) . '">', '</a>'); ! } ! else ! { ! $message .= '<br /><br />' . sprintf($mx_user->lang['SQL_ERROR_OCCURRED'], '', ''); ! } } } *************** *** 452,458 **** } } ! return $error; } --- 466,487 ---- } + if (strlen($message) > 1024) + { + // We need to define $msg_long_text here to circumvent text stripping. + global $msg_long_text; + $msg_long_text = $message; + + trigger_error(false, E_USER_ERROR); + } + + trigger_error($message, E_USER_ERROR); } ! if ($this->transaction) ! { ! $this->sql_transaction('rollback'); ! } ! ! return $this->sql_error_returned; } *************** *** 462,466 **** function sql_report($mode, $query = '') { ! global $mx_cache, $mx_starttime, $phpbb_root_path, $user; if (empty($_GET['explain'])) --- 491,495 ---- function sql_report($mode, $query = '') { ! global $mx_cache, $mx_starttime, $phpbb_root_path, $mx_user, $mx_root_path; if (empty($_GET['explain'])) *************** *** 473,477 **** $query = $this->query_hold; } ! switch ($mode) { --- 502,506 ---- $query = $this->query_hold; } ! switch ($mode) { *************** *** 486,528 **** $totaltime = $mtime[0] + $mtime[1] - $mx_starttime; ! echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'; ! echo '<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">'; ! echo '<head>'; ! echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />'; ! echo '<title>SQL Report</title>'; ! echo '<link href="' . $phpbb_root_path . 'adm/style/admin.css" rel="stylesheet" type="text/css" media="screen" />'; ! echo '<link href="' . $phpbb_root_path . 'adm/style/sql_report.css" rel="stylesheet" type="text/css" media="screen" />'; ! echo '</head>'; ! echo '<body id="errorpage">'; ! echo '<div id="wrap">'; ! echo ' <div id="page-header">'; ! echo ' <a href="' . htmlspecialchars(preg_replace('/&explain=([^&]*)/', '', $_SERVER['REQUEST_URI'])) . '">Return to previous page</a>'; ! echo ' </div>'; ! echo ' <div id="page-body">'; ! echo ' <div class="panel">'; ! echo ' <span class="corners-top"><span></span></span>'; ! echo ' <div id="content">'; ! echo ' <h1>SQL Report</h1>'; ! echo ' <table width="95%" cellspacing="1" cellpadding="4" border="0" align="center"><tr> ! <td height="40" align="center" valign="middle"><b>Page generated in ' . round($totaltime, 4) . " seconds with {$this->num_queries} queries" . (($this->cache_num_queries) ? " + {$this->cache_num_queries} " . (($this->cache_num_queries == 1) ? 'query' : 'queries') . ' returning data from cache' : '') . '</b></td> ! </tr><tr> ! <td align="center" nowrap="nowrap">Time spent on MySQL queries: <b>' . round($this->sql_time, 5) . 's</b> | Time spent on PHP: <b>' . round($totaltime - $this->sql_time, 5) . 's</b></td> ! </tr></table> ! <table width="95%" cellspacing="1" cellpadding="4" border="0" align="center"><tr> ! <td>' . $this->sql_report . '</td> ! </tr></table>'; ! echo ' </div>'; ! echo ' <span class="corners-bottom"><span></span></span>'; ! echo ' </div>'; ! echo ' </div>'; ! echo ' <div id="page-footer">'; ! echo ' Powered by phpBB © ' . date('Y') . ' <a href="http://www.phpbb.com/">phpBB Group</a>'; ! echo ' </div>'; ! echo '</div>'; ! echo '</body>'; ! echo '</html>'; ! exit; ! break; case 'stop': --- 515,560 ---- $totaltime = $mtime[0] + $mtime[1] - $mx_starttime; ! echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ! <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr"> ! <head> ! <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> ! <meta http-equiv="Content-Style-Type" content="text/css" /> ! <meta http-equiv="imagetoolbar" content="no" /> ! <title>SQL Report</title> ! <link href="' . $mx_root_path . 'templates/prosilver/admin/admin.css" rel="stylesheet" type="text/css" media="screen" /> ! </head> ! <body id="errorpage"> ! <div id="wrap"> ! <div id="page-header"> ! <a href="' . build_url('explain') . '">Return to previous page</a> ! </div> ! <div id="page-body"> ! <div id="acp"> ! <div class="panel"> ! <span class="corners-top"><span></span></span> ! <div id="content"> ! <h1>SQL Report</h1> ! <br /> ! <p><b>Page generated in ' . round($totaltime, 4) . " seconds with {$this->num_queries['normal']} queries" . (($this->num_queries['cached']) ? " + {$this->num_queries['cached']} " . (($this->num_queries['cached'] == 1) ? 'query' : 'queries') . ' returning data from cache' : '') . '</b></p> ! <p>Time spent on ' . $this->sql_layer . ' queries: <b>' . round($this->sql_time, 5) . 's</b> | Time spent on PHP: <b>' . round($totaltime - $this->sql_time, 5) . 's</b></p> ! ! <br /><br /> ! ' . $this->sql_report . ' ! </div> ! <span class="corners-bottom"><span></span></span> ! </div> ! </div> ! </div> ! <div id="page-footer"> ! Powered by phpBB © 2000, 2002, 2005, 2007 <a href="http://www.phpbb.com/">phpBB Group</a> ! </div> ! </div> ! </body> ! </html>'; ! ! exit_handler(); ! ! break; case 'stop': *************** *** 531,545 **** $this->sql_report .= ' - <hr width="100%"/><br /> ! <table class="bg" width="100%" cellspacing="1" cellpadding="4" border="0"> <tr> ! <th>Query #' . $this->num_queries . '</th> </tr> <tr> ! <td class="row1"><textarea style="font-family:\'Courier New\',monospace;width:100%" rows="5">' . preg_replace('/\t(AND|OR)(\W)/', "\$1\$2", htmlspecialchars(preg_replace('/[\s]*[\n\r\t]+[\n\r\s\t]*/', "\n", $query))) . '</textarea></td> </tr> ! </table> ' . $this->html_hold . ' ! <p align="center"> '; --- 563,583 ---- $this->sql_report .= ' ! <table cellspacing="1"> ! <thead> <tr> ! <th>Query #' . $this->num_queries['total'] . '</th> </tr> + </thead> + <tbody> <tr> ! <td class="row3"><textarea style="font-family:\'Courier New\',monospace;width:99%" rows="5" cols="10">' . preg_replace('/\t(AND|OR)(\W)/', "\$1\$2", htmlspecialchars(preg_replace('/[\s]*[\n\r\t]+[\n\r\s\t]*/', "\n", $query))) . '</textarea></td> </tr> ! </tbody> ! </table> ! ! ' . $this->html_hold . ' ! ! <p style="text-align: center;"> '; *************** *** 555,562 **** { $error = $this->sql_error(); ! $this->sql_report .= '<b style="color: red">FAILED</b> - ' . SQL_LAYER . ' Error ' . $error['code'] . ': ' . htmlspecialchars($error['message']); } ! $this->sql_report .= '</p>'; $this->sql_time += $endtime - $this->curtime; --- 593,600 ---- { $error = $this->sql_error(); ! $this->sql_report .= '<b style="color: red">FAILED</b> - ' . $this->sql_layer . ' Error ' . $error['code'] . ': ' . htmlspecialchars($error['message']); } ! $this->sql_report .= '</p><br /><br />'; $this->sql_time += $endtime - $this->curtime; *************** *** 566,570 **** $this->query_hold = $query; $this->html_hold = ''; ! $this->_sql_report($mode, $query); --- 604,608 ---- $this->query_hold = $query; $this->html_hold = ''; ! $this->_sql_report($mode, $query); *************** *** 573,590 **** break; ! case 'add_select_row': $html_table = func_get_arg(2); $row = func_get_arg(3); ! if (!$html_table && sizeof($row)) { $html_table = true; ! $this->html_hold .= '<table class="bg" width="100%" cellspacing="1" cellpadding="4" border="0" align="center"><tr>'; ! foreach (array_keys($row) as $val) { ! $this->html_hold .= '<th nowrap="nowrap">' . (($val) ? ucwords(str_replace('_', ' ', $val)) : ' ') . '</th>'; } $this->html_hold .= '</tr>'; --- 611,628 ---- break; ! case 'add_select_row': $html_table = func_get_arg(2); $row = func_get_arg(3); ! if (!$html_table && sizeof($row)) { $html_table = true; ! $this->html_hold .= '<table cellspacing="1"><tr>'; ! foreach (array_keys($row) as $val) { ! $this->html_hold .= '<th>' . (($val) ? ucwords(str_replace('_', ' ', $val)) : ' ') . '</th>'; } $this->html_hold .= '</tr>'; *************** *** 599,603 **** } $this->html_hold .= '</tr>'; ! return $html_table; --- 637,641 ---- } $this->html_hold .= '</tr>'; ! return $html_table; *************** *** 608,613 **** $this->_sql_report($mode, $query); - $this->cache_num_queries++; - break; --- 646,649 ---- *************** *** 621,626 **** $color = ($time_db > $time_cache) ? 'green' : 'red'; ! $this->sql_report .= '<hr width="100%"/><br /><table class="bg" width="100%" cellspacing="1" cellpadding="4" border="0"><tr><th>Query results obtained from the cache</th></tr><tr><td class="row1"><textarea style="font-family:\'Courier New\',monospace;width:100%" rows="5">' . preg_replace('/\t(AND|OR)(\W)/', "\$1\$2", htmlspecialchars(preg_replace('/[\s]*[\n\r\t]+[\n\r\s\t]*/', "\n", $query))) . '</textarea></td></tr></table><p align="center">'; ! $this->sql_report .= 'Before: ' . sprintf('%.5f', $this->curtime - $mx_starttime) . 's | After: ' . sprintf('%.5f', $endtime - $mx_starttime) . 's | Elapsed [cache]: <b style="color: ' . $color . '">' . sprintf('%.5f', ($time_cache)) . 's</b> | Elapsed [db]: <b>' . sprintf('%.5f', $time_db) . 's</b></p>'; // Pad the start time to not interfere with page timing --- 657,664 ---- $color = ($time_db > $time_cache) ? 'green' : 'red'; ! $this->sql_report .= '<table cellspacing="1"><thead><tr><th>Query results obtained from the cache</th></tr></thead><tbody><tr>'; ! $this->sql_report .= '<td class="row3"><textarea style="font-family:\'Courier New\',monospace;width:99%" rows="5" cols="10">' . preg_replace('/\t(AND|OR)(\W)/', "\$1\$2", htmlspecialchars(preg_replace('/[\s]*[\n\r\t]+[\n\r\s\t]*/', "\n", $query))) . '</textarea></td></tr></tbody></table>'; ! $this->sql_report .= '<p style="text-align: center;">'; ! $this->sql_report .= 'Before: ' . sprintf('%.5f', $this->curtime - $mx_starttime) . 's | After: ' . sprintf('%.5f', $endtime - $mx_starttime) . 's | Elapsed [cache]: <b style="color: ' . $color . '">' . sprintf('%.5f', ($time_cache)) . 's</b> | Elapsed [db]: <b>' . sprintf('%.5f', $time_db) . 's</b></p><br /><br />'; // Pad the start time to not interfere with page timing *************** *** 630,634 **** default: ! $this->_sql_report($mode, $query); --- 668,672 ---- default: ! $this->_sql_report($mode, $query); |