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
|
2007-10-05 14:36:34 +00:00
|
|
|
* @copyright (c) 2005 phpBB Group
|
2011-12-31 13:32:52 +00:00
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
2005-04-09 12:26:45 +00:00
|
|
|
*
|
|
|
|
*/
|
2003-03-17 10:54:23 +00:00
|
|
|
|
2013-09-10 14:01:09 +02:00
|
|
|
namespace phpbb\db\driver;
|
|
|
|
|
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
|
|
|
*/
|
2013-09-10 14:01:09 +02:00
|
|
|
class mysql extends \phpbb\db\driver\mysql_base
|
2003-03-17 10:54:23 +00:00
|
|
|
{
|
2007-05-05 04:53:43 +00:00
|
|
|
var $multi_insert = true;
|
2011-03-09 21:50:45 -05:00
|
|
|
var $connect_error = '';
|
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';
|
|
|
|
|
2011-03-09 21:50:45 -05:00
|
|
|
if ($this->persistency)
|
|
|
|
{
|
|
|
|
if (!function_exists('mysql_pconnect'))
|
|
|
|
{
|
|
|
|
$this->connect_error = 'mysql_pconnect function does not exist, is mysql extension installed?';
|
|
|
|
return $this->sql_error('');
|
|
|
|
}
|
|
|
|
$this->db_connect_id = @mysql_pconnect($this->server, $this->user, $sqlpassword);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!function_exists('mysql_connect'))
|
|
|
|
{
|
|
|
|
$this->connect_error = 'mysql_connect function does not exist, is mysql extension installed?';
|
|
|
|
return $this->sql_error('');
|
|
|
|
}
|
|
|
|
$this->db_connect_id = @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
|
2009-03-16 17:08:28 +00:00
|
|
|
if (version_compare($this->sql_server_info(true), '4.1.0', '>='))
|
2006-10-01 16:20:05 +00:00
|
|
|
{
|
|
|
|
@mysql_query("SET NAMES 'utf8'", $this->db_connect_id);
|
2008-09-04 12:01:47 +00:00
|
|
|
|
2007-08-14 12:27:35 +00:00
|
|
|
// enforce strict mode on databases that support it
|
2008-09-04 13:37:01 +00:00
|
|
|
if (version_compare($this->sql_server_info(true), '5.0.2', '>='))
|
2007-08-14 12:27:35 +00:00
|
|
|
{
|
|
|
|
$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
|
|
|
}
|
2008-09-04 13:37:01 +00:00
|
|
|
else if (version_compare($this->sql_server_info(true), '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
|
2008-09-04 12:01:47 +00:00
|
|
|
* @param bool $raw if true, only return the fetched sql_server_version
|
2010-06-06 08:42:27 -05:00
|
|
|
* @param bool $use_cache If true, it is safe to retrieve the value from the cache
|
2008-09-04 12:01:47 +00:00
|
|
|
* @return string sql server version
|
2006-07-09 16:23:57 +00:00
|
|
|
*/
|
2010-06-06 08:42:27 -05:00
|
|
|
function sql_server_info($raw = false, $use_cache = true)
|
2006-07-09 16:23:57 +00:00
|
|
|
{
|
2008-09-04 12:01:47 +00:00
|
|
|
global $cache;
|
|
|
|
|
2010-06-06 08:42:27 -05:00
|
|
|
if (!$use_cache || empty($cache) || ($this->sql_server_version = $cache->get('mysql_version')) === false)
|
2008-09-04 12:01:47 +00:00
|
|
|
{
|
|
|
|
$result = @mysql_query('SELECT VERSION() AS version', $this->db_connect_id);
|
|
|
|
$row = @mysql_fetch_assoc($result);
|
|
|
|
@mysql_free_result($result);
|
|
|
|
|
|
|
|
$this->sql_server_version = $row['version'];
|
|
|
|
|
2010-06-06 08:42:27 -05:00
|
|
|
if (!empty($cache) && $use_cache)
|
2008-09-04 12:01:47 +00:00
|
|
|
{
|
|
|
|
$cache->put('mysql_version', $this->sql_server_version);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ($raw) ? $this->sql_server_version : 'MySQL ' . $this->sql_server_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
|
2012-11-12 11:10:25 +01:00
|
|
|
if (defined('DEBUG'))
|
2004-12-31 13:58:41 +00:00
|
|
|
{
|
|
|
|
$this->sql_report('start', $query);
|
|
|
|
}
|
2003-08-28 00:22:18 +00:00
|
|
|
|
2013-01-02 14:36:14 -05:00
|
|
|
$this->query_result = ($cache && $cache_ttl) ? $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);
|
|
|
|
}
|
|
|
|
|
2012-11-12 11:10:25 +01:00
|
|
|
if (defined('DEBUG'))
|
2004-12-31 13:58:41 +00:00
|
|
|
{
|
|
|
|
$this->sql_report('stop', $query);
|
|
|
|
}
|
2003-03-17 10:54:23 +00:00
|
|
|
|
2013-01-02 14:36:14 -05:00
|
|
|
if ($cache && $cache_ttl)
|
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;
|
2012-12-20 04:35:30 -05:00
|
|
|
$this->query_result = $cache->sql_save($this, $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
|
|
|
}
|
2012-11-12 11:10:25 +01:00
|
|
|
else if (defined('DEBUG'))
|
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-09-02 13:27:37 +00:00
|
|
|
return $this->query_result;
|
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;
|
|
|
|
}
|
|
|
|
|
2013-01-02 14:36:14 -05:00
|
|
|
if ($cache && $cache->sql_exists($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;
|
|
|
|
}
|
|
|
|
|
2013-01-02 14:36:14 -05:00
|
|
|
if ($cache && $cache->sql_exists($query_id))
|
2006-08-01 16:14:14 +00:00
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2013-10-14 16:37:23 -05:00
|
|
|
if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
|
2006-08-01 16:14:14 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
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
|
|
|
{
|
2012-12-04 21:32:02 -05:00
|
|
|
if ($this->db_connect_id)
|
|
|
|
{
|
|
|
|
$error = array(
|
|
|
|
'message' => @mysql_error($this->db_connect_id),
|
|
|
|
'code' => @mysql_errno($this->db_connect_id),
|
|
|
|
);
|
|
|
|
}
|
2012-12-04 21:33:13 -05:00
|
|
|
else if (function_exists('mysql_error'))
|
2006-01-25 21:01:52 +00:00
|
|
|
{
|
2012-12-04 21:33:13 -05:00
|
|
|
$error = array(
|
2006-01-25 21:01:52 +00:00
|
|
|
'message' => @mysql_error(),
|
2012-12-04 21:33:13 -05:00
|
|
|
'code' => @mysql_errno(),
|
|
|
|
);
|
|
|
|
}
|
2012-12-04 21:32:02 -05:00
|
|
|
else
|
2006-01-25 21:01:52 +00:00
|
|
|
{
|
2012-12-04 21:33:13 -05:00
|
|
|
$error = array(
|
|
|
|
'message' => $this->connect_error,
|
|
|
|
'code' => '',
|
2006-01-25 21:01:52 +00:00
|
|
|
);
|
|
|
|
}
|
2006-06-02 13:26:27 +00:00
|
|
|
|
2012-12-04 21:32:02 -05:00
|
|
|
return $error;
|
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;
|
2008-09-04 12:01:47 +00:00
|
|
|
if (version_compare($this->sql_server_info(true), '5.0.37', '>=') && version_compare($this->sql_server_info(true), '5.1', '<'))
|
2007-04-08 09:43:21 +00:00
|
|
|
{
|
2008-09-04 12:01:47 +00:00
|
|
|
$test_prof = true;
|
2007-04-08 09:43:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|