diff options
Diffstat (limited to 'phpBB/phpbb/db/driver/mysqli.php')
| -rw-r--r-- | phpBB/phpbb/db/driver/mysqli.php | 125 | 
1 files changed, 79 insertions, 46 deletions
| diff --git a/phpBB/phpbb/db/driver/mysqli.php b/phpBB/phpbb/db/driver/mysqli.php index adc8f96302..d43e201526 100644 --- a/phpBB/phpbb/db/driver/mysqli.php +++ b/phpBB/phpbb/db/driver/mysqli.php @@ -1,9 +1,13 @@  <?php  /**  * -* @package dbal -* @copyright (c) 2005 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file.  *  */ @@ -13,7 +17,6 @@ namespace phpbb\db\driver;  * MySQLi Database Abstraction Layer  * mysqli-extension has to be compiled with:  * MySQL 4.1+ or MySQL 5.0+ -* @package dbal  */  class mysqli extends \phpbb\db\driver\mysql_base  { @@ -21,7 +24,7 @@ class mysqli extends \phpbb\db\driver\mysql_base  	var $connect_error = '';  	/** -	* Connect to server +	* {@inheritDoc}  	*/  	function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)  	{ @@ -31,8 +34,7 @@ class mysqli extends \phpbb\db\driver\mysql_base  			return $this->sql_error('');  		} -		// Mysqli extension supports persistent connection since PHP 5.3.0 -		$this->persistency = (version_compare(PHP_VERSION, '5.3.0', '>=')) ? $persistency : false; +		$this->persistency = $persistency;  		$this->user = $sqluser;  		// If persistent connection, set dbhost to localhost when empty and prepend it with 'p:' prefix @@ -57,7 +59,12 @@ class mysqli extends \phpbb\db\driver\mysql_base  			}  		} -		$this->db_connect_id = @mysqli_connect($this->server, $this->user, $sqlpassword, $this->dbname, $port, $socket); +		$this->db_connect_id = mysqli_init(); + +		if (!@mysqli_real_connect($this->db_connect_id, $this->server, $this->user, $sqlpassword, $this->dbname, $port, $socket, MYSQLI_CLIENT_FOUND_ROWS)) +		{ +			$this->db_connect_id = ''; +		}  		if ($this->db_connect_id && $this->dbname != '')  		{ @@ -67,10 +74,17 @@ class mysqli extends \phpbb\db\driver\mysql_base  			if (version_compare($this->sql_server_info(true), '5.0.2', '>='))  			{  				$result = @mysqli_query($this->db_connect_id, 'SELECT @@session.sql_mode AS sql_mode'); -				$row = @mysqli_fetch_assoc($result); -				@mysqli_free_result($result); +				if ($result) +				{ +					$row = mysqli_fetch_assoc($result); +					mysqli_free_result($result); -				$modes = array_map('trim', explode(',', $row['sql_mode'])); +					$modes = array_map('trim', explode(',', $row['sql_mode'])); +				} +				else +				{ +					$modes = array(); +				}  				// TRADITIONAL includes STRICT_ALL_TABLES and STRICT_TRANS_TABLES  				if (!in_array('TRADITIONAL', $modes)) @@ -96,10 +110,7 @@ class mysqli extends \phpbb\db\driver\mysql_base  	}  	/** -	* Version information about used database -	* @param bool $raw if true, only return the fetched sql_server_version -	* @param bool $use_cache If true, it is safe to retrieve the value from the cache -	* @return string sql server version +	* {@inheritDoc}  	*/  	function sql_server_info($raw = false, $use_cache = true)  	{ @@ -108,14 +119,17 @@ class mysqli extends \phpbb\db\driver\mysql_base  		if (!$use_cache || empty($cache) || ($this->sql_server_version = $cache->get('mysqli_version')) === false)  		{  			$result = @mysqli_query($this->db_connect_id, 'SELECT VERSION() AS version'); -			$row = @mysqli_fetch_assoc($result); -			@mysqli_free_result($result); +			if ($result) +			{ +				$row = mysqli_fetch_assoc($result); +				mysqli_free_result($result); -			$this->sql_server_version = $row['version']; +				$this->sql_server_version = $row['version']; -			if (!empty($cache) && $use_cache) -			{ -				$cache->put('mysqli_version', $this->sql_server_version); +				if (!empty($cache) && $use_cache) +				{ +					$cache->put('mysqli_version', $this->sql_server_version); +				}  			}  		} @@ -151,13 +165,7 @@ class mysqli extends \phpbb\db\driver\mysql_base  	}  	/** -	* Base query method -	* -	* @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 +	* {@inheritDoc}  	*/  	function sql_query($query = '', $cache_ttl = 0)  	{ @@ -170,6 +178,10 @@ class mysqli extends \phpbb\db\driver\mysql_base  			{  				$this->sql_report('start', $query);  			} +			else if (defined('PHPBB_DISPLAY_LOAD_TIME')) +			{ +				$this->curtime = microtime(true); +			}  			$this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false;  			$this->sql_add_num_queries($this->query_result); @@ -185,6 +197,15 @@ class mysqli extends \phpbb\db\driver\mysql_base  				{  					$this->sql_report('stop', $query);  				} +				else if (defined('PHPBB_DISPLAY_LOAD_TIME')) +				{ +					$this->sql_time += microtime(true) - $this->curtime; +				} + +				if (!$this->query_result) +				{ +					return false; +				}  				if ($cache && $cache_ttl)  				{ @@ -205,7 +226,7 @@ class mysqli extends \phpbb\db\driver\mysql_base  	}  	/** -	* Return number of affected rows +	* {@inheritDoc}  	*/  	function sql_affectedrows()  	{ @@ -213,7 +234,7 @@ class mysqli extends \phpbb\db\driver\mysql_base  	}  	/** -	* Fetch current row +	* {@inheritDoc}  	*/  	function sql_fetchrow($query_id = false)  	{ @@ -229,9 +250,9 @@ class mysqli extends \phpbb\db\driver\mysql_base  			return $cache->sql_fetchrow($query_id);  		} -		if ($query_id !== false) +		if ($query_id)  		{ -			$result = @mysqli_fetch_assoc($query_id); +			$result = mysqli_fetch_assoc($query_id);  			return $result !== null ? $result : false;  		} @@ -239,8 +260,7 @@ class mysqli extends \phpbb\db\driver\mysql_base  	}  	/** -	* Seek to given row number -	* rownum is zero-based +	* {@inheritDoc}  	*/  	function sql_rowseek($rownum, &$query_id)  	{ @@ -256,11 +276,11 @@ class mysqli extends \phpbb\db\driver\mysql_base  			return $cache->sql_rowseek($rownum, $query_id);  		} -		return ($query_id !== false) ? @mysqli_data_seek($query_id, $rownum) : false; +		return ($query_id) ? @mysqli_data_seek($query_id, $rownum) : false;  	}  	/** -	* Get last inserted id after insert statement +	* {@inheritDoc}  	*/  	function sql_nextid()  	{ @@ -268,7 +288,7 @@ class mysqli extends \phpbb\db\driver\mysql_base  	}  	/** -	* Free sql result +	* {@inheritDoc}  	*/  	function sql_freeresult($query_id = false)  	{ @@ -284,11 +304,21 @@ class mysqli extends \phpbb\db\driver\mysql_base  			return $cache->sql_freeresult($query_id);  		} -		return @mysqli_free_result($query_id); +		if (!$query_id) +		{ +			return false; +		} + +		if ($query_id === true) +		{ +			return true; +		} + +		return mysqli_free_result($query_id);  	}  	/** -	* Escape string used in sql query +	* {@inheritDoc}  	*/  	function sql_escape($msg)  	{ @@ -383,12 +413,12 @@ class mysqli extends \phpbb\db\driver\mysql_base  					if ($result = @mysqli_query($this->db_connect_id, "EXPLAIN $explain_query"))  					{ -						while ($row = @mysqli_fetch_assoc($result)) +						while ($row = mysqli_fetch_assoc($result))  						{  							$html_table = $this->sql_report('add_select_row', $query, $html_table, $row);  						} +						mysqli_free_result($result);  					} -					@mysqli_free_result($result);  					if ($html_table)  					{ @@ -403,7 +433,7 @@ class mysqli extends \phpbb\db\driver\mysql_base  						if ($result = @mysqli_query($this->db_connect_id, 'SHOW PROFILE ALL;'))  						{  							$this->html_hold .= '<br />'; -							while ($row = @mysqli_fetch_assoc($result)) +							while ($row = mysqli_fetch_assoc($result))  							{  								// make <unknown> HTML safe  								if (!empty($row['Source_function'])) @@ -421,8 +451,8 @@ class mysqli extends \phpbb\db\driver\mysql_base  								}  								$html_table = $this->sql_report('add_select_row', $query, $html_table, $row);  							} +							mysqli_free_result($result);  						} -						@mysqli_free_result($result);  						if ($html_table)  						{ @@ -440,11 +470,14 @@ class mysqli extends \phpbb\db\driver\mysql_base  				$endtime = $endtime[0] + $endtime[1];  				$result = @mysqli_query($this->db_connect_id, $query); -				while ($void = @mysqli_fetch_assoc($result)) +				if ($result)  				{ -					// Take the time spent on parsing rows into account +					while ($void = mysqli_fetch_assoc($result)) +					{ +						// Take the time spent on parsing rows into account +					} +					mysqli_free_result($result);  				} -				@mysqli_free_result($result);  				$splittime = explode(' ', microtime());  				$splittime = $splittime[0] + $splittime[1]; | 
