Vergleich inc/db_mysqli.php - 1.6.2 - 1.6.15

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 6Zeile 6
 * Website: http://mybb.com
* License: http://mybb.com/about/license
*

 * Website: http://mybb.com
* License: http://mybb.com/about/license
*

 * $Id: db_mysqli.php 5016 2010-06-12 00:24:02Z RyanGordon $

 * $Id$

 */

class DB_MySQLi

 */

class DB_MySQLi

Zeile 166Zeile 166
		// Actually connect to the specified servers
foreach(array('read', 'write') as $type)
{

		// Actually connect to the specified servers
foreach(array('read', 'write') as $type)
{

			if(!is_array($connections[$type]))

			if(!isset($connections[$type]) || !is_array($connections[$type]))

			{
break;
}

			{
break;
}

Zeile 184Zeile 184
			// Loop-de-loop
foreach($connections[$type] as $single_connection)
{

			// Loop-de-loop
foreach($connections[$type] as $single_connection)
{

				$connect_function = "mysqli_connect";
$persist = "";
if($single_connection['pconnect'] && version_compare(PHP_VERSION, '5.3.0', '>='))

				$persist = '';
$connect_function = 'mysqli_connect';
if(isset($single_connection['pconnect']) && version_compare(PHP_VERSION, '5.3.0', '>='))

				{

				{

					$persist = "p:";

					$persist = 'p:';

				}

				}

				
$link = $type."_link";

$this->get_execution_time();


$link = "{$type}_link";

$this->get_execution_time();


// Specified a custom port for this connection?


// Specified a custom port for this connection?

				list($hostname, $port) = explode(":", $single_connection['hostname'], 2);
if($port)






				$port = 0;
if(strstr($single_connection['hostname'],':'))
{
list($hostname, $port) = explode(":", $single_connection['hostname'], 2);
}

if($port)

				{
$this->$link = @$connect_function($persist.$hostname, $single_connection['username'], $single_connection['password'], "", $port);
}
else
{
$this->$link = @$connect_function($persist.$single_connection['hostname'], $single_connection['username'], $single_connection['password']);

				{
$this->$link = @$connect_function($persist.$hostname, $single_connection['username'], $single_connection['password'], "", $port);
}
else
{
$this->$link = @$connect_function($persist.$single_connection['hostname'], $single_connection['username'], $single_connection['password']);

				}

				}


$time_spent = $this->get_execution_time();
$this->query_time += $time_spent;


$time_spent = $this->get_execution_time();
$this->query_time += $time_spent;

Zeile 267Zeile 272
			$slave_success = @mysqli_select_db($this->write_link, $database) or $this->error("[WRITE] Unable to select slave database", $this->write_link);

$success = ($master_success && $slave_success ? true : false);

			$slave_success = @mysqli_select_db($this->write_link, $database) or $this->error("[WRITE] Unable to select slave database", $this->write_link);

$success = ($master_success && $slave_success ? true : false);

		}

		}

		else
{
$success = $master_success;

		else
{
$success = $master_success;

Zeile 291Zeile 296
	 * @param string The query SQL.
* @param boolean 1 if hide errors, 0 if not.
* @param integer 1 if executes on slave database, 0 if not.

	 * @param string The query SQL.
* @param boolean 1 if hide errors, 0 if not.
* @param integer 1 if executes on slave database, 0 if not.

	 * @return resource The query data.
*/

	 * @return resource The query data.
*/

	function query($string, $hide_errors=0, $write_query=0)
{
global $pagestarttime, $db, $mybb;

	function query($string, $hide_errors=0, $write_query=0)
{
global $pagestarttime, $db, $mybb;

Zeile 330Zeile 335
	
/**
* Execute a write query on the slave database

	
/**
* Execute a write query on the slave database

	 *

	 *

	 * @param string The query SQL.
* @param boolean 1 if hide errors, 0 if not.
* @return resource The query data.

	 * @param string The query SQL.
* @param boolean 1 if hide errors, 0 if not.
* @return resource The query data.

Zeile 349Zeile 354
	function explain_query($string, $qtime)
{
global $plugins;

	function explain_query($string, $qtime)
{
global $plugins;

 

$debug_extra = '';

		if($plugins->current_hook)
{
$debug_extra = "<div style=\"float_right\">(Plugin Hook: {$plugins->current_hook})</div>";

		if($plugins->current_hook)
{
$debug_extra = "<div style=\"float_right\">(Plugin Hook: {$plugins->current_hook})</div>";

Zeile 361Zeile 368
				"<td colspan=\"8\" style=\"background-color: #ccc;\">{$debug_extra}<div><strong>#".$this->query_count." - Select Query</strong></div></td>\n".
"</tr>\n".
"<tr>\n".

				"<td colspan=\"8\" style=\"background-color: #ccc;\">{$debug_extra}<div><strong>#".$this->query_count." - Select Query</strong></div></td>\n".
"</tr>\n".
"<tr>\n".

				"<td colspan=\"8\" style=\"background-color: #fefefe;\"><span style=\"font-family: Courier; font-size: 14px;\">".$string."</span></td>\n".

				"<td colspan=\"8\" style=\"background-color: #fefefe;\"><span style=\"font-family: Courier; font-size: 14px;\">".htmlspecialchars_uni($string)."</span></td>\n".

				"</tr>\n".
"<tr style=\"background-color: #efefef;\">\n".
"<td><strong>table</strong></td>\n".

				"</tr>\n".
"<tr style=\"background-color: #efefef;\">\n".
"<td><strong>table</strong></td>\n".

Zeile 391Zeile 398
			$this->explain .=
"<tr>\n".
"<td colspan=\"8\" style=\"background-color: #fff;\">Query Time: ".$qtime."</td>\n".

			$this->explain .=
"<tr>\n".
"<td colspan=\"8\" style=\"background-color: #fff;\">Query Time: ".$qtime."</td>\n".

				"</tr>\n".
"</table>\n".
"<br />\n";

				"</tr>\n".
"</table>\n".
"<br />\n";

		}
else
{

		}
else
{

Zeile 418Zeile 425

/**
* Return a result array for a query.


/**
* Return a result array for a query.

	 *
* @param resource The query data.

	 *
* @param resource The query data.

	 * @param constant The type of array to return.
* @return array The array of results.
*/

	 * @param constant The type of array to return.
* @return array The array of results.
*/

	function fetch_array($query)

	function fetch_array($query, $resulttype=MYSQLI_ASSOC)

	{

	{

		$array = mysqli_fetch_assoc($query);












		switch($resulttype)
{
case MYSQLI_NUM:
case MYSQLI_BOTH:
break;
default:
$resulttype = MYSQLI_ASSOC;
break;
}

$array = mysqli_fetch_array($query, $resulttype);


		return $array;
}


		return $array;
}


Zeile 444Zeile 462
		}
$array = $this->fetch_array($query);
return $array[$field];

		}
$array = $this->fetch_array($query);
return $array[$field];

	}

/**

	}

/**

	 * Moves internal row pointer to the next row
*
* @param resource The query ID.

	 * Moves internal row pointer to the next row
*
* @param resource The query ID.

Zeile 459Zeile 477

/**
* Return the number of rows resulting from a query.


/**
* Return the number of rows resulting from a query.

	 *

	 *

	 * @param resource The query data.
* @return int The number of rows in the result.
*/

	 * @param resource The query data.
* @return int The number of rows in the result.
*/

Zeile 496Zeile 514
	 * Return an error number.
*
* @return int The error number of the current error.

	 * Return an error number.
*
* @return int The error number of the current error.

	 */

	 */

	function error_number()
{
if($this->current_link)

	function error_number()
{
if($this->current_link)

		{

		{

			return mysqli_errno($this->current_link);			

			return mysqli_errno($this->current_link);			

		}

		}

		else
{
return mysqli_connect_errno();

		else
{
return mysqli_connect_errno();

		}
}

/**

		}
}

/**

	 * Return an error string.
*
* @return string The explanation for the current error.

	 * Return an error string.
*
* @return string The explanation for the current error.

Zeile 519Zeile 537
		if($this->current_link)
{
return mysqli_error($this->current_link);

		if($this->current_link)
{
return mysqli_error($this->current_link);

		}
else
{

		}
else
{

			return mysqli_connect_error();
}
}

			return mysqli_connect_error();
}
}

Zeile 534Zeile 552
	function error($string="")
{
if($this->error_reporting)

	function error($string="")
{
if($this->error_reporting)

		{

		{

			if(class_exists("errorHandler"))
{
global $error_handler;

			if(class_exists("errorHandler"))
{
global $error_handler;

Zeile 596Zeile 614
	function list_tables($database, $prefix='')
{
if($prefix)

	function list_tables($database, $prefix='')
{
if($prefix)

		{

		{

			$query = $this->query("SHOW TABLES FROM `$database` LIKE '".$this->escape_string($prefix)."%'");

			$query = $this->query("SHOW TABLES FROM `$database` LIKE '".$this->escape_string($prefix)."%'");

		}

		}

		else

		else

		{

		{

			$query = $this->query("SHOW TABLES FROM `$database`");
}


			$query = $this->query("SHOW TABLES FROM `$database`");
}


Zeile 609Zeile 627
			$tables[] = $table;
}
return $tables;

			$tables[] = $table;
}
return $tables;

	}

	}


/**
* Check if a table exists in a database.


/**
* Check if a table exists in a database.

Zeile 623Zeile 641
		$query = $this->write_query("
SHOW TABLES
LIKE '{$this->table_prefix}$table'

		$query = $this->write_query("
SHOW TABLES
LIKE '{$this->table_prefix}$table'

		");
$exists = $this->num_rows($query);

if($exists > 0)
{
return true;
}
else
{
return false;
}
}

		");
$exists = $this->num_rows($query);

if($exists > 0)
{
return true;
}
else
{
return false;
}
}


/**
* Check if a field exists in a database.


/**
* Check if a field exists in a database.

Zeile 659Zeile 677
		else
{
return false;

		else
{
return false;

		}

		}

	}

/**

	}

/**

Zeile 696Zeile 714
		$query = "SELECT ".$fields." FROM ".$this->table_prefix.$table;

if($conditions != "")

		$query = "SELECT ".$fields." FROM ".$this->table_prefix.$table;

if($conditions != "")

		{

		{

			$query .= " WHERE ".$conditions;
}


			$query .= " WHERE ".$conditions;
}


Zeile 746Zeile 764
	
/**
* Build one query for multiple inserts from a multidimensional array.

	
/**
* Build one query for multiple inserts from a multidimensional array.

	 *
* @param string The table name to perform the query on.

	 *
* @param string The table name to perform the query on.

	 * @param array An array of inserts.
* @return int The insert ID if available
*/

	 * @param array An array of inserts.
* @return int The insert ID if available
*/

Zeile 760Zeile 778
		// Field names
$fields = array_keys($array[0]);
$fields = "`".implode("`,`", $fields)."`";

		// Field names
$fields = array_keys($array[0]);
$fields = "`".implode("`,`", $fields)."`";





		$insert_rows = array();
foreach($array as $values)
{

		$insert_rows = array();
foreach($array as $values)
{

Zeile 797Zeile 815
		$quote = "'";

if($no_quote == true)

		$quote = "'";

if($no_quote == true)

		{

		{

			$quote = "";
}


			$quote = "";
}


Zeile 807Zeile 825
			$comma = ', ';
}


			$comma = ', ';
}


		if(!empty($where))
{
$query .= " WHERE $where";
}


		if(!empty($where))
{
$query .= " WHERE $where";
}


		if(!empty($limit))
{
$query .= " LIMIT $limit";

		if(!empty($limit))
{
$query .= " LIMIT $limit";

Zeile 825Zeile 843

/**
* Build a delete query.


/**
* Build a delete query.

	 *

	 *

	 * @param string The table name to perform the query on.
* @param string An optional where clause for the query.
* @param string An optional limit clause for the query.
* @return resource The query data.
*/
function delete_query($table, $where="", $limit="")

	 * @param string The table name to perform the query on.
* @param string An optional where clause for the query.
* @param string An optional limit clause for the query.
* @return resource The query data.
*/
function delete_query($table, $where="", $limit="")

	{

	{

		$query = "";
if(!empty($where))
{
$query .= " WHERE $where";
}
if(!empty($limit))

		$query = "";
if(!empty($where))
{
$query .= " WHERE $where";
}
if(!empty($limit))

		{

		{

			$query .= " LIMIT $limit";
}
return $this->write_query("DELETE FROM {$this->table_prefix}$table $query");

			$query .= " LIMIT $limit";
}
return $this->write_query("DELETE FROM {$this->table_prefix}$table $query");

Zeile 853Zeile 871
	 */
function escape_string($string)
{

	 */
function escape_string($string)
{

 
		if($this->db_encoding == 'utf8')
{
$string = validate_utf8_string($string, false);
}
elseif($this->db_encoding == 'utf8mb4')
{
$string = validate_utf8_string($string);
}


		if(function_exists("mysqli_real_escape_string") && $this->read_link)
{
$string = mysqli_real_escape_string($this->read_link, $string);

		if(function_exists("mysqli_real_escape_string") && $this->read_link)
{
$string = mysqli_real_escape_string($this->read_link, $string);

Zeile 998Zeile 1025
		$query = $this->write_query("SHOW TABLE STATUS LIKE '{$this->table_prefix}$table'");
$status = $this->fetch_array($query);
$table_type = my_strtoupper($status['Engine']);

		$query = $this->write_query("SHOW TABLE STATUS LIKE '{$this->table_prefix}$table'");
$status = $this->fetch_array($query);
$table_type = my_strtoupper($status['Engine']);

		if($version >= '3.23.23' && $table_type == 'MYISAM')





		if(version_compare($version, '3.23.23', '>=') && ($table_type == 'MYISAM' || $table_type == 'ARIA'))
{
return true;
}
elseif(version_compare($version, '5.6', '>=') && $table_type == 'INNODB')

		{
return true;
}

		{
return true;
}

Zeile 1015Zeile 1046
	{
$version = $this->get_version();
$supports_fulltext = $this->supports_fulltext($table);

	{
$version = $this->get_version();
$supports_fulltext = $this->supports_fulltext($table);

		if($version >= '4.0.1' && $supports_fulltext == true)

		if(version_compare($version, '4.0.1', '>=') && $supports_fulltext == true)

		{
return true;
}

		{
return true;
}

Zeile 1240Zeile 1271
			'latin5' => 'ISO 8859-9 Turkish',
'armscii8' => 'ARMSCII-8 Armenian',
'utf8' => 'UTF-8 Unicode',

			'latin5' => 'ISO 8859-9 Turkish',
'armscii8' => 'ARMSCII-8 Armenian',
'utf8' => 'UTF-8 Unicode',

 
			'utf8mb4' => '4-Byte UTF-8 Unicode (requires MySQL 5.5.3 or above)',

			'ucs2' => 'UCS-2 Unicode',
'cp866' => 'DOS Russian',
'keybcs2' => 'DOS Kamenicky Czech-Slovak',

			'ucs2' => 'UCS-2 Unicode',
'cp866' => 'DOS Russian',
'keybcs2' => 'DOS Kamenicky Czech-Slovak',

Zeile 1288Zeile 1320
			'latin5' => 'latin5_turkish_ci',
'armscii8' => 'armscii8_general_ci',
'utf8' => 'utf8_general_ci',

			'latin5' => 'latin5_turkish_ci',
'armscii8' => 'armscii8_general_ci',
'utf8' => 'utf8_general_ci',

 
			'utf8mb4' => 'utf8mb4_general_ci',

			'ucs2' => 'ucs2_general_ci',
'cp866' => 'cp866_general_ci',
'keybcs2' => 'keybcs2_general_ci',

			'ucs2' => 'ucs2_general_ci',
'cp866' => 'cp866_general_ci',
'keybcs2' => 'keybcs2_general_ci',