2005-04-22 17:44:36 +00:00
|
|
|
<?php
|
2007-10-05 14:36:34 +00:00
|
|
|
/**
|
2005-04-22 17:44:36 +00:00
|
|
|
*
|
2005-08-17 15:57:50 +00:00
|
|
|
* @package dbal
|
2005-04-22 17:44:36 +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-22 17:44:36 +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);
|
2005-04-22 17:44:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* MySQLi Database Abstraction Layer
|
2005-11-28 18:38:49 +00:00
|
|
|
* mysqli-extension has to be compiled with:
|
|
|
|
* MySQL 4.1+ or MySQL 5.0+
|
2006-06-13 21:06:29 +00:00
|
|
|
* @package dbal
|
2005-04-22 17:44:36 +00:00
|
|
|
*/
|
2005-08-17 15:57:50 +00:00
|
|
|
class dbal_mysqli extends dbal
|
2005-04-22 17:44:36 +00:00
|
|
|
{
|
2007-05-05 04:53:43 +00:00
|
|
|
var $multi_insert = true;
|
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
/**
|
|
|
|
* Connect to server
|
|
|
|
*/
|
2007-02-19 04:12:13 +00:00
|
|
|
function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false , $new_link = false)
|
2005-04-22 17:44:36 +00:00
|
|
|
{
|
2011-06-19 19:03:53 +08:00
|
|
|
// Mysqli extension supports persistent connection since PHP 5.3.0
|
|
|
|
$this->persistency = (version_compare(PHP_VERSION, '5.3.0', '>=')) ? $persistency : false;
|
2005-04-22 17:44:36 +00:00
|
|
|
$this->user = $sqluser;
|
2011-06-19 19:03:53 +08:00
|
|
|
|
|
|
|
// If persistent connection, set dbhost to localhost when empty and prepend it with 'p:' prefix
|
|
|
|
$this->server = ($this->persistency) ? 'p:' . (($sqlserver) ? $sqlserver : 'localhost') : $sqlserver;
|
|
|
|
|
2005-04-22 17:44:36 +00:00
|
|
|
$this->dbname = $database;
|
2006-04-08 17:34:04 +00:00
|
|
|
$port = (!$port) ? NULL : $port;
|
2005-04-22 17:44:36 +00:00
|
|
|
|
2011-06-21 00:21:42 +08:00
|
|
|
// If port is set and it is not numeric, most likely mysqli socket is set.
|
|
|
|
// Try to map it to the $socket parameter.
|
|
|
|
$socket = NULL;
|
|
|
|
if ($port)
|
|
|
|
{
|
2011-06-21 22:03:19 +08:00
|
|
|
if (is_numeric($port))
|
2011-06-21 00:21:42 +08:00
|
|
|
{
|
|
|
|
$port = (int) $port;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$socket = $port;
|
|
|
|
$port = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->db_connect_id = @mysqli_connect($this->server, $this->user, $sqlpassword, $this->dbname, $port, $socket);
|
2005-04-22 17:44:36 +00:00
|
|
|
|
|
|
|
if ($this->db_connect_id && $this->dbname != '')
|
|
|
|
{
|
2006-10-05 00:55:27 +00:00
|
|
|
@mysqli_query($this->db_connect_id, "SET NAMES 'utf8'");
|
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 12:01:47 +00:00
|
|
|
if (version_compare($this->sql_server_info(true), '5.0.2', '>='))
|
2007-08-14 12:27:35 +00:00
|
|
|
{
|
|
|
|
$result = @mysqli_query($this->db_connect_id, 'SELECT @@session.sql_mode AS sql_mode');
|
|
|
|
$row = @mysqli_fetch_assoc($result);
|
|
|
|
@mysqli_free_result($result);
|
2008-09-04 12:01:47 +00:00
|
|
|
|
2007-08-14 12:27:35 +00:00
|
|
|
$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);
|
|
|
|
@mysqli_query($this->db_connect_id, "SET SESSION sql_mode='{$mode}'");
|
|
|
|
}
|
2006-10-05 00:55:27 +00:00
|
|
|
return $this->db_connect_id;
|
2005-04-22 17:44:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->sql_error('');
|
|
|
|
}
|
|
|
|
|
2006-07-09 16:23:57 +00:00
|
|
|
/**
|
|
|
|
* Version information about used database
|
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('mysqli_version')) === false)
|
2008-09-04 12:01:47 +00:00
|
|
|
{
|
|
|
|
$result = @mysqli_query($this->db_connect_id, 'SELECT VERSION() AS version');
|
|
|
|
$row = @mysqli_fetch_assoc($result);
|
|
|
|
@mysqli_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('mysqli_version', $this->sql_server_version);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ($raw) ? $this->sql_server_version : 'MySQL(i) ' . $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')
|
2005-04-22 17:44:36 +00:00
|
|
|
{
|
|
|
|
switch ($status)
|
|
|
|
{
|
|
|
|
case 'begin':
|
2006-06-06 20:53:46 +00:00
|
|
|
return @mysqli_autocommit($this->db_connect_id, false);
|
2006-06-02 13:26:27 +00:00
|
|
|
break;
|
2005-04-22 17:44:36 +00:00
|
|
|
|
|
|
|
case 'commit':
|
|
|
|
$result = @mysqli_commit($this->db_connect_id);
|
|
|
|
@mysqli_autocommit($this->db_connect_id, true);
|
2006-06-06 20:53:46 +00:00
|
|
|
return $result;
|
2006-06-02 13:26:27 +00:00
|
|
|
break;
|
2005-04-22 17:44:36 +00:00
|
|
|
|
|
|
|
case 'rollback':
|
|
|
|
$result = @mysqli_rollback($this->db_connect_id);
|
|
|
|
@mysqli_autocommit($this->db_connect_id, true);
|
2006-06-06 20:53:46 +00:00
|
|
|
return $result;
|
2006-06-02 13:26:27 +00:00
|
|
|
break;
|
2005-04-22 17:44:36 +00:00
|
|
|
}
|
|
|
|
|
2006-06-06 20:53:46 +00:00
|
|
|
return true;
|
2005-04-22 17:44:36 +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
|
|
|
*/
|
2005-04-22 17:44:36 +00:00
|
|
|
function sql_query($query = '', $cache_ttl = 0)
|
|
|
|
{
|
|
|
|
if ($query != '')
|
|
|
|
{
|
|
|
|
global $cache;
|
|
|
|
|
|
|
|
// EXPLAIN only in extra debug mode
|
|
|
|
if (defined('DEBUG_EXTRA'))
|
|
|
|
{
|
|
|
|
$this->sql_report('start', $query);
|
|
|
|
}
|
|
|
|
|
|
|
|
$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);
|
|
|
|
|
2006-10-03 20:38:03 +00:00
|
|
|
if ($this->query_result === false)
|
2005-04-22 17:44:36 +00:00
|
|
|
{
|
|
|
|
if (($this->query_result = @mysqli_query($this->db_connect_id, $query)) === false)
|
|
|
|
{
|
|
|
|
$this->sql_error($query);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined('DEBUG_EXTRA'))
|
|
|
|
{
|
|
|
|
$this->sql_report('stop', $query);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($cache_ttl && method_exists($cache, 'sql_save'))
|
|
|
|
{
|
|
|
|
$cache->sql_save($query, $this->query_result, $cache_ttl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (defined('DEBUG_EXTRA'))
|
|
|
|
{
|
|
|
|
$this->sql_report('fromcache', $query);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-09-02 13:27:37 +00:00
|
|
|
return $this->query_result;
|
2005-04-22 17:44:36 +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;
|
2005-04-22 17:44:36 +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
|
|
|
// MySQL 4.1+ no longer supports -1 in limit queries
|
|
|
|
$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);
|
2005-04-22 17:44:36 +00:00
|
|
|
}
|
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
/**
|
|
|
|
* Return number of affected rows
|
|
|
|
*/
|
2005-04-22 17:44:36 +00:00
|
|
|
function sql_affectedrows()
|
|
|
|
{
|
|
|
|
return ($this->db_connect_id) ? @mysqli_affected_rows($this->db_connect_id) : false;
|
|
|
|
}
|
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
/**
|
|
|
|
* Fetch current row
|
|
|
|
*/
|
2005-04-22 17:44:36 +00:00
|
|
|
function sql_fetchrow($query_id = false)
|
|
|
|
{
|
|
|
|
global $cache;
|
|
|
|
|
2006-10-04 15:15:40 +00:00
|
|
|
if ($query_id === false)
|
2005-04-22 17:44:36 +00:00
|
|
|
{
|
|
|
|
$query_id = $this->query_result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_object($query_id) && isset($cache->sql_rowset[$query_id]))
|
|
|
|
{
|
|
|
|
return $cache->sql_fetchrow($query_id);
|
|
|
|
}
|
|
|
|
|
2011-10-13 16:43:11 +02:00
|
|
|
if ($query_id !== false)
|
|
|
|
{
|
|
|
|
$result = @mysqli_fetch_assoc($query_id);
|
|
|
|
return $result !== null ? $result : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2005-04-22 17:44:36 +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)
|
2005-04-22 17:44:36 +00:00
|
|
|
{
|
2006-08-01 16:14:14 +00:00
|
|
|
global $cache;
|
|
|
|
|
2006-10-04 15:15:40 +00:00
|
|
|
if ($query_id === false)
|
2005-04-22 17:44:36 +00:00
|
|
|
{
|
|
|
|
$query_id = $this->query_result;
|
|
|
|
}
|
|
|
|
|
2006-08-02 09:13:39 +00:00
|
|
|
if (!is_object($query_id) && isset($cache->sql_rowset[$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) ? @mysqli_data_seek($query_id, $rownum) : false;
|
2005-04-22 17:44:36 +00:00
|
|
|
}
|
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
/**
|
|
|
|
* Get last inserted id after insert statement
|
|
|
|
*/
|
2005-04-22 17:44:36 +00:00
|
|
|
function sql_nextid()
|
|
|
|
{
|
|
|
|
return ($this->db_connect_id) ? @mysqli_insert_id($this->db_connect_id) : false;
|
|
|
|
}
|
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
/**
|
|
|
|
* Free sql result
|
|
|
|
*/
|
2005-04-22 17:44:36 +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)
|
2005-04-22 17:44:36 +00:00
|
|
|
{
|
|
|
|
$query_id = $this->query_result;
|
|
|
|
}
|
|
|
|
|
2006-08-02 09:13:39 +00:00
|
|
|
if (!is_object($query_id) && isset($cache->sql_rowset[$query_id]))
|
2005-04-22 17:44:36 +00:00
|
|
|
{
|
2006-08-01 16:14:14 +00:00
|
|
|
return $cache->sql_freeresult($query_id);
|
2005-04-22 17:44:36 +00:00
|
|
|
}
|
2005-10-07 23:00:41 +00:00
|
|
|
|
2006-08-01 16:14:14 +00:00
|
|
|
return @mysqli_free_result($query_id);
|
2005-04-22 17:44:36 +00:00
|
|
|
}
|
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
/**
|
|
|
|
* Escape string used in sql query
|
|
|
|
*/
|
2005-04-22 17:44:36 +00:00
|
|
|
function sql_escape($msg)
|
|
|
|
{
|
|
|
|
return @mysqli_real_escape_string($this->db_connect_id, $msg);
|
|
|
|
}
|
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-06-02 13:26:27 +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()
|
2005-04-22 17:44:36 +00:00
|
|
|
{
|
2006-04-08 17:34:04 +00:00
|
|
|
if (!$this->db_connect_id)
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'message' => @mysqli_connect_error(),
|
|
|
|
'code' => @mysqli_connect_errno()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2005-08-17 15:57:50 +00:00
|
|
|
return array(
|
2005-04-22 17:44:36 +00:00
|
|
|
'message' => @mysqli_error($this->db_connect_id),
|
|
|
|
'code' => @mysqli_errno($this->db_connect_id)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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()
|
2005-04-22 17:44:36 +00:00
|
|
|
{
|
2005-10-07 23:00:41 +00:00
|
|
|
return @mysqli_close($this->db_connect_id);
|
|
|
|
}
|
2005-04-22 17:44:36 +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(mysqli_get_server_info($this->db_connect_id), 'community') !== false)
|
|
|
|
{
|
|
|
|
$ver = mysqli_get_server_version($this->db_connect_id);
|
2007-08-14 12:27:35 +00:00
|
|
|
if ($ver >= 50037 && $ver < 50100)
|
2007-04-08 09:43:21 +00:00
|
|
|
{
|
|
|
|
$test_prof = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-22 17:44:36 +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))
|
2005-04-22 17:44:36 +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;
|
2005-04-22 17:44:36 +00:00
|
|
|
|
2007-04-08 09:43:21 +00:00
|
|
|
// begin profiling
|
|
|
|
if ($test_prof)
|
|
|
|
{
|
|
|
|
@mysqli_query($this->db_connect_id, 'SET profiling = 1;');
|
|
|
|
}
|
|
|
|
|
2005-04-22 17:44:36 +00:00
|
|
|
if ($result = @mysqli_query($this->db_connect_id, "EXPLAIN $explain_query"))
|
|
|
|
{
|
|
|
|
while ($row = @mysqli_fetch_assoc($result))
|
|
|
|
{
|
2005-10-07 23:00:41 +00:00
|
|
|
$html_table = $this->sql_report('add_select_row', $query, $html_table, $row);
|
2005-04-22 17:44:36 +00:00
|
|
|
}
|
|
|
|
}
|
2005-10-07 23:00:41 +00:00
|
|
|
@mysqli_free_result($result);
|
2005-04-22 17:44:36 +00:00
|
|
|
|
|
|
|
if ($html_table)
|
|
|
|
{
|
2005-10-07 23:00:41 +00:00
|
|
|
$this->html_hold .= '</table>';
|
2005-04-22 17:44:36 +00:00
|
|
|
}
|
2007-04-08 09:43:21 +00:00
|
|
|
|
|
|
|
if ($test_prof)
|
|
|
|
{
|
|
|
|
$html_table = false;
|
|
|
|
|
|
|
|
// get the last profile
|
|
|
|
if ($result = @mysqli_query($this->db_connect_id, 'SHOW PROFILE ALL;'))
|
|
|
|
{
|
|
|
|
$this->html_hold .= '<br />';
|
|
|
|
while ($row = @mysqli_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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@mysqli_free_result($result);
|
|
|
|
|
|
|
|
if ($html_table)
|
|
|
|
{
|
|
|
|
$this->html_hold .= '</table>';
|
|
|
|
}
|
|
|
|
|
|
|
|
@mysqli_query($this->db_connect_id, 'SET profiling = 0;');
|
|
|
|
}
|
2005-04-22 17:44:36 +00:00
|
|
|
}
|
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
break;
|
2005-04-22 17:44:36 +00:00
|
|
|
|
|
|
|
case 'fromcache':
|
|
|
|
$endtime = explode(' ', microtime());
|
|
|
|
$endtime = $endtime[0] + $endtime[1];
|
|
|
|
|
|
|
|
$result = @mysqli_query($this->db_connect_id, $query);
|
|
|
|
while ($void = @mysqli_fetch_assoc($result))
|
|
|
|
{
|
|
|
|
// Take the time spent on parsing rows into account
|
|
|
|
}
|
2005-10-07 23:00:41 +00:00
|
|
|
@mysqli_free_result($result);
|
|
|
|
|
2005-04-22 17:44:36 +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);
|
2005-04-22 17:44:36 +00:00
|
|
|
|
2005-10-07 23:00:41 +00:00
|
|
|
break;
|
2005-04-22 17:44:36 +00:00
|
|
|
}
|
|
|
|
}
|
2005-08-17 15:57:50 +00:00
|
|
|
}
|
2005-04-22 17:44:36 +00:00
|
|
|
|
|
|
|
?>
|