1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-12 03:34:04 +02:00

- add building multi insert to dbal

- fix sql explain in mysql4 layer


git-svn-id: file:///svn/phpbb/trunk@5242 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen
2005-10-02 18:18:52 +00:00
parent 1a18e36684
commit 1d688c6b8d
2 changed files with 117 additions and 42 deletions

View File

@@ -20,11 +20,14 @@ if (!defined('SQL_LAYER'))
/**
* @package dbal
* MySQL4 Database Abstraction Layer
* Minimum Requirement is 4.0+/4.1+
* Minimum Requirement is 4.0+ (4.1+ compatible)
*/
class dbal_mysql4 extends dbal
{
/**
* Connect to sql server
*/
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false)
{
$this->persistency = $persistency;
@@ -319,15 +322,12 @@ class dbal_mysql4 extends dbal
function _sql_report($mode, $query = '')
{
global $cache, $starttime, $phpbb_root_path;
static $curtime, $query_hold, $html_hold;
static $sql_report = '';
static $cache_num_queries = 0;
switch ($mode)
{
case 'start':
$query_hold = $query;
$html_hold = '';
$this->query_hold = $query;
$this->html_hold = '';
$explain_query = $query;
if (preg_match('/UPDATE ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m))
@@ -341,7 +341,7 @@ class dbal_mysql4 extends dbal
if (preg_match('/^SELECT/', $explain_query))
{
$html_table = FALSE;
$html_table = false;
if ($result = mysql_query("EXPLAIN $explain_query", $this->db_connect_id))
{
@@ -349,35 +349,35 @@ class dbal_mysql4 extends dbal
{
if (!$html_table && sizeof($row))
{
$html_table = TRUE;
$html_hold .= '<table class="bg" width="100%" cellspacing="1" cellpadding="4" border="0" align="center"><tr>';
$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)
{
$html_hold .= '<th nowrap="nowrap">' . (($val) ? ucwords(str_replace('_', ' ', $val)) : '&nbsp;') . '</th>';
$this->html_hold .= '<th nowrap="nowrap">' . (($val) ? ucwords(str_replace('_', ' ', $val)) : '&nbsp;') . '</th>';
}
$html_hold .= '</tr>';
$this->html_hold .= '</tr>';
}
$html_hold .= '<tr>';
$this->html_hold .= '<tr>';
$class = 'row1';
foreach (array_values($row) as $val)
{
$class = ($class == 'row1') ? 'row2' : 'row1';
$html_hold .= '<td class="' . $class . '">' . (($val) ? $val : '&nbsp;') . '</td>';
$this->html_hold .= '<td class="' . $class . '">' . (($val) ? $val : '&nbsp;') . '</td>';
}
$html_hold .= '</tr>';
$this->html_hold .= '</tr>';
}
}
if ($html_table)
{
$html_hold .= '</table>';
$this->html_hold .= '</table>';
}
}
$curtime = explode(' ', microtime());
$curtime = $curtime[0] + $curtime[1];
$this->curtime = explode(' ', microtime());
$this->curtime = $this->curtime[0] + $this->curtime[1];
break;
case 'fromcache':
@@ -392,19 +392,19 @@ class dbal_mysql4 extends dbal
$splittime = explode(' ', microtime());
$splittime = $splittime[0] + $splittime[1];
$time_cache = $endtime - $curtime;
$time_cache = $endtime - $this->curtime;
$time_db = $splittime - $endtime;
$color = ($time_db > $time_cache) ? 'green' : 'red';
$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 .= '<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">';
$sql_report .= 'Before: ' . sprintf('%.5f', $curtime - $starttime) . 's | After: ' . sprintf('%.5f', $endtime - $starttime) . 's | Elapsed [cache]: <b style="color: ' . $color . '">' . sprintf('%.5f', ($time_cache)) . 's</b> | Elapsed [db]: <b>' . sprintf('%.5f', $time_db) . 's</b></p>';
$this->sql_report .= 'Before: ' . sprintf('%.5f', $this->curtime - $starttime) . 's | After: ' . sprintf('%.5f', $endtime - $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
$starttime += $time_db;
mysql_free_result($result);
$cache_num_queries++;
$this->cache_num_queries++;
break;
}
}