2003-03-17 10:54:23 +00:00
|
|
|
<?php
|
2007-10-05 14:36:34 +00:00
|
|
|
/**
|
2005-04-09 12:26:45 +00:00
|
|
|
*
|
2005-08-17 15:57:50 +00:00
|
|
|
* @package dbal
|
2005-04-09 12:26:45 +00:00
|
|
|
* @version $Id$
|
2007-10-05 14:36:34 +00:00
|
|
|
* @copyright (c) 2005 phpBB Group
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
2005-04-09 12:26:45 +00:00
|
|
|
*
|
|
|
|
*/
|
2003-03-17 10:54:23 +00:00
|
|
|
|
2006-03-19 14:23:21 +00:00
|
|
|
/**
|
2006-10-14 14:56:46 +00:00
|
|
|
* @ignore
|
2006-03-19 14:23:21 +00:00
|
|
|
*/
|
|
|
|
if (!defined('IN_PHPBB'))
|
|
|
|
{
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2006-10-14 14:56:46 +00:00
|
|
|
include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
|
2003-03-17 10:54:23 +00:00
|
|
|
|
2005-04-09 12:26:45 +00:00
|
|
|
/**
|
2006-10-01 16:20:05 +00:00
|
|
|
* MySQL4 Database Abstraction Layer
|
|
|
|
* Compatible with:
|
|
|
|
* MySQL 3.23+
|
|
|
|
* MySQL 4.0+
|
|
|
|
* MySQL 4.1+
|
|
|
|
* MySQL 5.0+
|
2006-06-13 21:06:29 +00:00
|
|
|
* @package dbal
|
2005-04-09 12:26:45 +00:00
|
|
|
*/
|
2005-08-17 15:57:50 +00:00
|
|
|
class dbal_mysql extends dbal
|
2003-03-17 10:54:23 +00:00
|
|
|
{
|
2006-10-03 18:35:59 +00:00
|
|
|
var $mysql_version;
|
2007-05-05 04:53:43 +00:00
|
|
|
var $multi_insert = true;
|
2006-10-03 18:35:59 +00:00
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
/**
|
|
|
|
* Connect to server
|
2006-08-22 21:26:06 +00:00
|
|
|
* @access public
|
2005-10-07 23:00:41 +00:00
|
|
|
*/
|
2007-02-19 04:12:13 +00:00
|
|
|
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)
|
2003-03-17 10:54:23 +00:00
|
|
|
{
|
|
|
|
$this->persistency = $persistency;
|
|
|
|
$this->user = $sqluser;
|
|
|
|
$this->server = $sqlserver . (($port) ? ':' . $port : '');
|
|
|
|
$this->dbname = $database;
|
|
|
|
|
2006-11-03 17:50:39 +00:00
|
|
|
$this->sql_layer = 'mysql4';
|
|
|
|
|
2007-02-19 04:12:13 +00:00
|
|
|
$this->db_connect_id = ($this->persistency) ? @mysql_pconnect($this->server, $this->user, $sqlpassword, $new_link) : @mysql_connect($this->server, $this->user, $sqlpassword, $new_link);
|
2003-03-17 10:54:23 +00:00
|
|
|
|
|
|
|
if ($this->db_connect_id && $this->dbname != '')
|
|
|
|
{
|
2007-02-19 04:12:13 +00:00
|
|
|
if (@mysql_select_db($this->dbname, $this->db_connect_id))
|
2003-03-17 10:54:23 +00:00
|
|
|
{
|
2006-10-01 16:20:05 +00:00
|
|
|
// Determine what version we are using and if it natively supports UNICODE
|
2006-10-03 18:35:59 +00:00
|
|
|
$this->mysql_version = mysql_get_server_info($this->db_connect_id);
|
2006-10-01 16:20:05 +00:00
|
|
|
|
2006-10-03 18:35:59 +00:00
|
|
|
if (version_compare($this->mysql_version, '4.1.3', '>='))
|
2006-10-01 16:20:05 +00:00
|
|
|
{
|
|
|
|
@mysql_query("SET NAMES 'utf8'", $this->db_connect_id);
|
2007-08-14 12:27:35 +00:00
|
|
|
// enforce strict mode on databases that support it
|
|
|
|
if (version_compare($this->mysql_version, '5.0.2', '>='))
|
|
|
|
{
|
|
|
|
$result = @mysql_query('SELECT @@session.sql_mode AS sql_mode', $this->db_connect_id);
|
|
|
|
$row = @mysql_fetch_assoc($result);
|
|
|
|
@mysql_free_result($result);
|
|
|
|
$modes = array_map('trim', explode(',', $row['sql_mode']));
|
|
|
|
|
|
|
|
// TRADITIONAL includes STRICT_ALL_TABLES and STRICT_TRANS_TABLES
|
|
|
|
if (!in_array('TRADITIONAL', $modes))
|
|
|
|
{
|
|
|
|
if (!in_array('STRICT_ALL_TABLES', $modes))
|
|
|
|
{
|
|
|
|
$modes[] = 'STRICT_ALL_TABLES';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!in_array('STRICT_TRANS_TABLES', $modes))
|
|
|
|
{
|
|
|
|
$modes[] = 'STRICT_TRANS_TABLES';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$mode = implode(',', $modes);
|
|
|
|
@mysql_query("SET SESSION sql_mode='{$mode}'", $this->db_connect_id);
|
|
|
|
}
|
2006-10-01 16:20:05 +00:00
|
|
|
}
|
2006-10-14 14:56:46 +00:00
|
|
|
else if (version_compare($this->mysql_version, '4.0.0', '<'))
|
2006-10-01 16:20:05 +00:00
|
|
|
{
|
2006-10-14 14:56:46 +00:00
|
|
|
$this->sql_layer = 'mysql';
|
2006-10-01 16:20:05 +00:00
|
|
|
}
|
|
|
|
|
2003-03-17 10:54:23 +00:00
|
|
|
return $this->db_connect_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-12 17:11:43 +00:00
|
|
|
return $this->sql_error('');
|
2003-03-17 10:54:23 +00:00
|
|
|
}
|
|
|
|
|
2006-07-09 16:23:57 +00:00
|
|
|
/**
|
|
|
|
* Version information about used database
|
|
|
|
*/
|
|
|
|
function sql_server_info()
|
|
|
|
{
|
2006-10-03 18:35:59 +00:00
|
|
|
return 'MySQL ' . $this->mysql_version;
|
2006-07-09 16:23:57 +00:00
|
|
|
}
|
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
/**
|
2006-06-06 20:53:46 +00:00
|
|
|
* SQL Transaction
|
2006-08-22 21:26:06 +00:00
|
|
|
* @access private
|
2005-10-07 23:00:41 +00:00
|
|
|
*/
|
2006-06-06 20:53:46 +00:00
|
|
|
function _sql_transaction($status = 'begin')
|
2003-03-17 10:54:23 +00:00
|
|
|
{
|
|
|
|
switch ($status)
|
|
|
|
{
|
|
|
|
case 'begin':
|
2006-06-06 20:53:46 +00:00
|
|
|
return @mysql_query('BEGIN', $this->db_connect_id);
|
2006-06-02 13:26:27 +00:00
|
|
|
break;
|
2003-03-17 10:54:23 +00:00
|
|
|
|
|
|
|
case 'commit':
|
2006-06-06 20:53:46 +00:00
|
|
|
return @mysql_query('COMMIT', $this->db_connect_id);
|
2006-06-02 13:26:27 +00:00
|
|
|
break;
|
2003-03-17 10:54:23 +00:00
|
|
|
|
|
|
|
case 'rollback':
|
2006-06-06 20:53:46 +00:00
|
|
|
return @mysql_query('ROLLBACK', $this->db_connect_id);
|
2006-06-02 13:26:27 +00:00
|
|
|
break;
|
2003-03-17 10:54:23 +00:00
|
|
|
}
|
|
|
|
|
2006-06-06 20:53:46 +00:00
|
|
|
return true;
|
2003-03-17 10:54:23 +00:00
|
|
|
}
|
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
/**
|
|
|
|
* Base query method
|
2006-08-01 16:14:14 +00:00
|
|
|
*
|
|
|
|
* @param string $query Contains the SQL query which shall be executed
|
|
|
|
* @param int $cache_ttl Either 0 to avoid caching or the time in seconds which the result shall be kept in cache
|
|
|
|
* @return mixed When casted to bool the returned value returns true on success and false on failure
|
|
|
|
*
|
|
|
|
* @access public
|
2005-10-07 23:00:41 +00:00
|
|
|
*/
|
2003-11-27 00:02:16 +00:00
|
|
|
function sql_query($query = '', $cache_ttl = 0)
|
2003-03-17 10:54:23 +00:00
|
|
|
{
|
|
|
|
if ($query != '')
|
|
|
|
{
|
|
|
|
global $cache;
|
2003-08-28 00:22:18 +00:00
|
|
|
|
2004-12-31 13:58:41 +00:00
|
|
|
// EXPLAIN only in extra debug mode
|
|
|
|
if (defined('DEBUG_EXTRA'))
|
|
|
|
{
|
|
|
|
$this->sql_report('start', $query);
|
|
|
|
}
|
2003-08-28 00:22:18 +00:00
|
|
|
|
2003-11-27 00:02:16 +00:00
|
|
|
$this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false;
|
2006-05-20 13:20:38 +00:00
|
|
|
$this->sql_add_num_queries($this->query_result);
|
2003-03-17 10:54:23 +00:00
|
|
|
|
2006-10-03 20:38:03 +00:00
|
|
|
if ($this->query_result === false)
|
2003-08-10 18:51:07 +00:00
|
|
|
{
|
2003-08-27 16:31:54 +00:00
|
|
|
if (($this->query_result = @mysql_query($query, $this->db_connect_id)) === false)
|
2003-03-17 10:54:23 +00:00
|
|
|
{
|
|
|
|
$this->sql_error($query);
|
|
|
|
}
|
|
|
|
|
2004-12-31 13:58:41 +00:00
|
|
|
if (defined('DEBUG_EXTRA'))
|
|
|
|
{
|
|
|
|
$this->sql_report('stop', $query);
|
|
|
|
}
|
2003-03-17 10:54:23 +00:00
|
|
|
|
2003-11-27 00:02:16 +00:00
|
|
|
if ($cache_ttl && method_exists($cache, 'sql_save'))
|
2003-04-24 18:19:45 +00:00
|
|
|
{
|
2004-12-31 13:58:41 +00:00
|
|
|
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
2003-11-27 00:02:16 +00:00
|
|
|
$cache->sql_save($query, $this->query_result, $cache_ttl);
|
2003-04-24 18:19:45 +00:00
|
|
|
}
|
2006-03-17 12:51:32 +00:00
|
|
|
else if (strpos($query, 'SELECT') === 0 && $this->query_result)
|
2003-08-12 16:03:29 +00:00
|
|
|
{
|
2004-12-31 13:58:41 +00:00
|
|
|
$this->open_queries[(int) $this->query_result] = $this->query_result;
|
2003-08-12 16:03:29 +00:00
|
|
|
}
|
2003-03-17 10:54:23 +00:00
|
|
|
}
|
2004-12-31 13:58:41 +00:00
|
|
|
else if (defined('DEBUG_EXTRA'))
|
2003-08-28 00:22:18 +00:00
|
|
|
{
|
|
|
|
$this->sql_report('fromcache', $query);
|
|
|
|
}
|
2003-03-17 10:54:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-08-14 18:38:41 +00:00
|
|
|
return ($this->query_result !== false) ? $this->query_result : false;
|
2003-03-17 10:54:23 +00:00
|
|
|
}
|
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
/**
|
|
|
|
* Build LIMIT query
|
|
|
|
*/
|
2007-10-05 14:36:34 +00:00
|
|
|
function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
|
2006-06-02 13:26:27 +00:00
|
|
|
{
|
2007-01-17 18:41:49 +00:00
|
|
|
$this->query_result = false;
|
2003-03-17 10:54:23 +00:00
|
|
|
|
2007-01-17 18:41:49 +00:00
|
|
|
// if $total is set to 0 we do not want to limit the number of rows
|
|
|
|
if ($total == 0)
|
2006-06-02 13:26:27 +00:00
|
|
|
{
|
2007-01-17 18:41:49 +00:00
|
|
|
// Having a value of -1 was always a bug
|
|
|
|
$total = '18446744073709551615';
|
2006-06-02 13:26:27 +00:00
|
|
|
}
|
2007-01-17 18:41:49 +00:00
|
|
|
|
|
|
|
$query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total);
|
|
|
|
|
|
|
|
return $this->sql_query($query, $cache_ttl);
|
2003-03-17 10:54:23 +00:00
|
|
|
}
|
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
/**
|
|
|
|
* Return number of affected rows
|
|
|
|
*/
|
2003-03-17 10:54:23 +00:00
|
|
|
function sql_affectedrows()
|
|
|
|
{
|
|
|
|
return ($this->db_connect_id) ? @mysql_affected_rows($this->db_connect_id) : false;
|
|
|
|
}
|
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
/**
|
|
|
|
* Fetch current row
|
|
|
|
*/
|
2005-01-04 22:07:53 +00:00
|
|
|
function sql_fetchrow($query_id = false)
|
2003-03-17 10:54:23 +00:00
|
|
|
{
|
|
|
|
global $cache;
|
|
|
|
|
2006-10-04 15:15:40 +00:00
|
|
|
if ($query_id === false)
|
2003-03-17 10:54:23 +00:00
|
|
|
{
|
|
|
|
$query_id = $this->query_result;
|
|
|
|
}
|
|
|
|
|
2004-12-31 13:58:41 +00:00
|
|
|
if (isset($cache->sql_rowset[$query_id]))
|
2003-03-17 10:54:23 +00:00
|
|
|
{
|
|
|
|
return $cache->sql_fetchrow($query_id);
|
|
|
|
}
|
|
|
|
|
2006-10-04 15:15:40 +00:00
|
|
|
return ($query_id !== false) ? @mysql_fetch_assoc($query_id) : false;
|
2003-03-17 10:54:23 +00:00
|
|
|
}
|
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
/**
|
|
|
|
* Seek to given row number
|
|
|
|
* rownum is zero-based
|
|
|
|
*/
|
2007-06-12 21:24:22 +00:00
|
|
|
function sql_rowseek($rownum, &$query_id)
|
2003-03-17 10:54:23 +00:00
|
|
|
{
|
2006-08-01 16:14:14 +00:00
|
|
|
global $cache;
|
|
|
|
|
2006-10-04 15:15:40 +00:00
|
|
|
if ($query_id === false)
|
2003-03-17 10:54:23 +00:00
|
|
|
{
|
|
|
|
$query_id = $this->query_result;
|
|
|
|
}
|
|
|
|
|
2006-08-01 16:14:14 +00:00
|
|
|
if (isset($cache->sql_rowset[$query_id]))
|
|
|
|
{
|
2006-09-23 11:10:37 +00:00
|
|
|
return $cache->sql_rowseek($rownum, $query_id);
|
2006-08-01 16:14:14 +00:00
|
|
|
}
|
|
|
|
|
2006-10-04 15:15:40 +00:00
|
|
|
return ($query_id !== false) ? @mysql_data_seek($query_id, $rownum) : false;
|
2003-03-17 10:54:23 +00:00
|
|
|
}
|
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
/**
|
|
|
|
* Get last inserted id after insert statement
|
|
|
|
*/
|
2003-03-17 10:54:23 +00:00
|
|
|
function sql_nextid()
|
|
|
|
{
|
|
|
|
return ($this->db_connect_id) ? @mysql_insert_id($this->db_connect_id) : false;
|
|
|
|
}
|
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
/**
|
|
|
|
* Free sql result
|
|
|
|
*/
|
2003-03-17 10:54:23 +00:00
|
|
|
function sql_freeresult($query_id = false)
|
|
|
|
{
|
2006-08-01 16:14:14 +00:00
|
|
|
global $cache;
|
|
|
|
|
2006-10-04 15:15:40 +00:00
|
|
|
if ($query_id === false)
|
2003-03-17 10:54:23 +00:00
|
|
|
{
|
|
|
|
$query_id = $this->query_result;
|
|
|
|
}
|
|
|
|
|
2006-08-01 16:14:14 +00:00
|
|
|
if (isset($cache->sql_rowset[$query_id]))
|
|
|
|
{
|
|
|
|
return $cache->sql_freeresult($query_id);
|
|
|
|
}
|
|
|
|
|
2004-12-31 13:58:41 +00:00
|
|
|
if (isset($this->open_queries[(int) $query_id]))
|
2004-05-26 18:55:28 +00:00
|
|
|
{
|
2004-12-31 13:58:41 +00:00
|
|
|
unset($this->open_queries[(int) $query_id]);
|
|
|
|
return @mysql_free_result($query_id);
|
2004-05-26 18:55:28 +00:00
|
|
|
}
|
|
|
|
|
2004-12-31 13:58:41 +00:00
|
|
|
return false;
|
2003-03-17 10:54:23 +00:00
|
|
|
}
|
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
/**
|
|
|
|
* Escape string used in sql query
|
|
|
|
*/
|
2003-03-17 10:54:23 +00:00
|
|
|
function sql_escape($msg)
|
|
|
|
{
|
2006-02-16 10:26:52 +00:00
|
|
|
if (!$this->db_connect_id)
|
|
|
|
{
|
|
|
|
return @mysql_real_escape_string($msg);
|
|
|
|
}
|
2006-10-01 16:20:05 +00:00
|
|
|
|
2006-02-16 10:26:52 +00:00
|
|
|
return @mysql_real_escape_string($msg, $this->db_connect_id);
|
2003-03-17 10:54:23 +00:00
|
|
|
}
|
2006-05-05 22:06:17 +00:00
|
|
|
|
2007-06-24 12:49:13 +00:00
|
|
|
/**
|
|
|
|
* Build LIKE expression
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
function _sql_like_expression($expression)
|
|
|
|
{
|
|
|
|
return $expression;
|
|
|
|
}
|
|
|
|
|
2006-05-05 22:06:17 +00:00
|
|
|
/**
|
|
|
|
* Build db-specific query data
|
2006-08-22 21:26:06 +00:00
|
|
|
* @access private
|
2006-05-05 22:06:17 +00:00
|
|
|
*/
|
|
|
|
function _sql_custom_build($stage, $data)
|
|
|
|
{
|
|
|
|
switch ($stage)
|
|
|
|
{
|
|
|
|
case 'FROM':
|
|
|
|
$data = '(' . $data . ')';
|
|
|
|
break;
|
|
|
|
}
|
2006-06-02 13:26:27 +00:00
|
|
|
|
2006-05-05 22:06:17 +00:00
|
|
|
return $data;
|
|
|
|
}
|
2006-10-01 16:20:05 +00:00
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
/**
|
|
|
|
* return sql error array
|
2006-08-22 21:26:06 +00:00
|
|
|
* @access private
|
2005-10-07 23:00:41 +00:00
|
|
|
*/
|
|
|
|
function _sql_error()
|
2003-03-17 10:54:23 +00:00
|
|
|
{
|
2006-01-25 21:01:52 +00:00
|
|
|
if (!$this->db_connect_id)
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'message' => @mysql_error(),
|
|
|
|
'code' => @mysql_errno()
|
|
|
|
);
|
|
|
|
}
|
2006-06-02 13:26:27 +00:00
|
|
|
|
2005-08-17 15:57:50 +00:00
|
|
|
return array(
|
2006-01-22 13:06:13 +00:00
|
|
|
'message' => @mysql_error($this->db_connect_id),
|
|
|
|
'code' => @mysql_errno($this->db_connect_id)
|
2003-06-12 17:11:43 +00:00
|
|
|
);
|
2003-03-17 10:54:23 +00:00
|
|
|
}
|
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
/**
|
|
|
|
* Close sql connection
|
2006-08-22 21:26:06 +00:00
|
|
|
* @access private
|
2005-10-07 23:00:41 +00:00
|
|
|
*/
|
|
|
|
function _sql_close()
|
2003-08-28 00:22:18 +00:00
|
|
|
{
|
2005-10-07 23:00:41 +00:00
|
|
|
return @mysql_close($this->db_connect_id);
|
|
|
|
}
|
2003-08-28 00:22:18 +00:00
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
/**
|
|
|
|
* Build db-specific report
|
2006-08-22 21:26:06 +00:00
|
|
|
* @access private
|
2005-10-07 23:00:41 +00:00
|
|
|
*/
|
|
|
|
function _sql_report($mode, $query = '')
|
|
|
|
{
|
2007-04-08 09:43:21 +00:00
|
|
|
static $test_prof;
|
|
|
|
|
|
|
|
// current detection method, might just switch to see the existance of INFORMATION_SCHEMA.PROFILING
|
|
|
|
if ($test_prof === null)
|
|
|
|
{
|
|
|
|
$test_prof = false;
|
|
|
|
if (strpos($this->mysql_version, 'community') !== false)
|
|
|
|
{
|
|
|
|
$ver = substr($this->mysql_version, 0, strpos($this->mysql_version, '-'));
|
|
|
|
if (version_compare($ver, '5.0.37', '>=') && version_compare($ver, '5.1', '<'))
|
|
|
|
{
|
|
|
|
$test_prof = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-28 00:22:18 +00:00
|
|
|
switch ($mode)
|
|
|
|
{
|
|
|
|
case 'start':
|
|
|
|
|
|
|
|
$explain_query = $query;
|
|
|
|
if (preg_match('/UPDATE ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m))
|
|
|
|
{
|
|
|
|
$explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2];
|
|
|
|
}
|
2005-10-07 23:00:41 +00:00
|
|
|
else if (preg_match('/DELETE FROM ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m))
|
2003-08-28 00:22:18 +00:00
|
|
|
{
|
|
|
|
$explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (preg_match('/^SELECT/', $explain_query))
|
|
|
|
{
|
2005-10-07 23:00:41 +00:00
|
|
|
$html_table = false;
|
2003-08-28 00:22:18 +00:00
|
|
|
|
2007-04-08 09:43:21 +00:00
|
|
|
// begin profiling
|
|
|
|
if ($test_prof)
|
|
|
|
{
|
|
|
|
@mysql_query('SET profiling = 1;', $this->db_connect_id);
|
|
|
|
}
|
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
if ($result = @mysql_query("EXPLAIN $explain_query", $this->db_connect_id))
|
2003-08-28 00:22:18 +00:00
|
|
|
{
|
2005-10-07 23:00:41 +00:00
|
|
|
while ($row = @mysql_fetch_assoc($result))
|
2003-08-28 00:22:18 +00:00
|
|
|
{
|
2005-10-07 23:00:41 +00:00
|
|
|
$html_table = $this->sql_report('add_select_row', $query, $html_table, $row);
|
2003-08-28 00:22:18 +00:00
|
|
|
}
|
|
|
|
}
|
2005-10-07 23:00:41 +00:00
|
|
|
@mysql_free_result($result);
|
2003-08-28 00:22:18 +00:00
|
|
|
|
|
|
|
if ($html_table)
|
|
|
|
{
|
2005-10-07 23:00:41 +00:00
|
|
|
$this->html_hold .= '</table>';
|
2003-08-28 00:22:18 +00:00
|
|
|
}
|
2007-04-08 09:43:21 +00:00
|
|
|
|
|
|
|
if ($test_prof)
|
|
|
|
{
|
|
|
|
$html_table = false;
|
|
|
|
|
|
|
|
// get the last profile
|
|
|
|
if ($result = @mysql_query('SHOW PROFILE ALL;', $this->db_connect_id))
|
|
|
|
{
|
|
|
|
$this->html_hold .= '<br />';
|
|
|
|
while ($row = @mysql_fetch_assoc($result))
|
|
|
|
{
|
|
|
|
// make <unknown> HTML safe
|
|
|
|
if (!empty($row['Source_function']))
|
|
|
|
{
|
|
|
|
$row['Source_function'] = str_replace(array('<', '>'), array('<', '>'), $row['Source_function']);
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove unsupported features
|
|
|
|
foreach ($row as $key => $val)
|
|
|
|
{
|
|
|
|
if ($val === null)
|
|
|
|
{
|
|
|
|
unset($row[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$html_table = $this->sql_report('add_select_row', $query, $html_table, $row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@mysql_free_result($result);
|
|
|
|
|
|
|
|
if ($html_table)
|
|
|
|
{
|
|
|
|
$this->html_hold .= '</table>';
|
|
|
|
}
|
|
|
|
|
|
|
|
@mysql_query('SET profiling = 0;', $this->db_connect_id);
|
|
|
|
}
|
2003-08-28 00:22:18 +00:00
|
|
|
}
|
2003-11-27 00:02:16 +00:00
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
break;
|
2003-08-28 00:22:18 +00:00
|
|
|
|
|
|
|
case 'fromcache':
|
|
|
|
$endtime = explode(' ', microtime());
|
2003-11-27 00:02:16 +00:00
|
|
|
$endtime = $endtime[0] + $endtime[1];
|
2003-08-28 00:22:18 +00:00
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
$result = @mysql_query($query, $this->db_connect_id);
|
|
|
|
while ($void = @mysql_fetch_assoc($result))
|
2003-11-27 00:02:16 +00:00
|
|
|
{
|
|
|
|
// Take the time spent on parsing rows into account
|
|
|
|
}
|
2005-10-07 23:00:41 +00:00
|
|
|
@mysql_free_result($result);
|
|
|
|
|
2003-11-27 00:02:16 +00:00
|
|
|
$splittime = explode(' ', microtime());
|
|
|
|
$splittime = $splittime[0] + $splittime[1];
|
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
$this->sql_report('record_fromcache', $query, $endtime, $splittime);
|
2003-08-28 00:22:18 +00:00
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
break;
|
2003-08-28 00:22:18 +00:00
|
|
|
}
|
|
|
|
}
|
2005-08-17 15:57:50 +00:00
|
|
|
}
|
2003-03-17 10:54:23 +00:00
|
|
|
|
|
|
|
?>
|