Vergleich inc/db_mysqli.php - 1.8.6 - 1.8.16

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 72Zeile 72
	 * @var mysqli
*/
public $current_link;

	 * @var mysqli
*/
public $current_link;

 

/**
* The database name.
*
* @var string
*/
public $database;


/**
* Explanation of a query.


/**
* Explanation of a query.

Zeile 103Zeile 110

/**
* The extension used to run the SQL database


/**
* The extension used to run the SQL database

	 *

	 *

	 * @var string
*/
public $engine = "mysqli";

	 * @var string
*/
public $engine = "mysqli";

Zeile 133Zeile 140
	 * Stores previous run query type: 1 => write; 0 => read
*
* @var int

	 * Stores previous run query type: 1 => write; 0 => read
*
* @var int

	 */

	 */

	protected $last_query_type = 0;

/**

	protected $last_query_type = 0;

/**

Zeile 148Zeile 155
		if(array_key_exists('hostname', $config))
{
$connections['read'][] = $config;

		if(array_key_exists('hostname', $config))
{
$connections['read'][] = $config;

		}

		}

		else
// Connecting to more than one server
{

		else
// Connecting to more than one server
{

Zeile 178Zeile 185
			if(!isset($connections[$type]) || !is_array($connections[$type]))
{
break;

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

			}

			}


if(array_key_exists('hostname', $connections[$type]))
{


if(array_key_exists('hostname', $connections[$type]))
{

Zeile 192Zeile 199

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


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

			{

			{

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

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

Zeile 233Zeile 240
				{
$this->connections[] = "<span style=\"color: red\">[FAILED] [".strtoupper($type)."] {$single_connection['username']}@{$single_connection['hostname']}</span>";
}

				{
$this->connections[] = "<span style=\"color: red\">[FAILED] [".strtoupper($type)."] {$single_connection['username']}@{$single_connection['hostname']}</span>";
}

			}
}


			}
}


		// No write server was specified (simple connection or just multiple servers) - mirror write link
if(!array_key_exists('write', $connections))
{

		// No write server was specified (simple connection or just multiple servers) - mirror write link
if(!array_key_exists('write', $connections))
{

Zeile 263Zeile 270

$this->current_link = &$this->read_link;
return $this->read_link;


$this->current_link = &$this->read_link;
return $this->read_link;

	}


	}


	/**
* Selects the database to use.
*

	/**
* Selects the database to use.
*

Zeile 273Zeile 280
	 */
function select_db($database)
{

	 */
function select_db($database)
{

 
		$this->database = $database;


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

		$master_success = @mysqli_select_db($this->read_link, $database) or $this->error("[READ] Unable to select database", $this->read_link);
if($this->write_link)
{
$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 && $slave_success ? true : false);
}
else

Zeile 306Zeile 315
	 * @return mysqli_result The query data.
*/
function query($string, $hide_errors=0, $write_query=0)

	 * @return mysqli_result The query data.
*/
function query($string, $hide_errors=0, $write_query=0)

	{
global $mybb;

get_execution_time();


	{
global $mybb;

get_execution_time();


		// Only execute write queries on master server
if(($write_query || $this->last_query_type) && $this->write_link)
{

		// Only execute write queries on master server
if(($write_query || $this->last_query_type) && $this->write_link)
{

Zeile 632Zeile 641
	{
if($prefix)
{

	{
if($prefix)
{

			$query = $this->query("
SELECT `TABLE_NAME` FROM INFORMATION_SCHEMA.TABLES
WHERE `TABLE_SCHEMA` = '$database' AND `TABLE_TYPE` = 'BASE TABLE'
AND `TABLE_NAME` LIKE '".$this->escape_string($prefix)."%'
");
}
else
{
$query = $this->query("
SELECT `TABLE_NAME` FROM INFORMATION_SCHEMA.TABLES
WHERE `TABLE_SCHEMA` = '$database' AND `TABLE_TYPE` = 'BASE TABLE'
");








			if(version_compare($this->get_version(), '5.0.2', '>='))
{
$query = $this->query("SHOW FULL TABLES FROM `$database` WHERE table_type = 'BASE TABLE' AND `Tables_in_$database` LIKE '".$this->escape_string($prefix)."%'");
}
else
{
$query = $this->query("SHOW TABLES FROM `$database` LIKE '".$this->escape_string($prefix)."%'");
}
}
else
{
if(version_compare($this->get_version(), '5.0.2', '>='))
{
$query = $this->query("SHOW FULL TABLES FROM `$database` WHERE table_type = 'BASE TABLE'");
}
else
{
$query = $this->query("SHOW TABLES FROM `$database`");
}

		}

$tables = array();
while(list($table) = mysqli_fetch_array($query))
{
$tables[] = $table;

		}

$tables = array();
while(list($table) = mysqli_fetch_array($query))
{
$tables[] = $table;

		}


		}


		return $tables;
}


		return $tables;
}


Zeile 663Zeile 680
	function table_exists($table)
{
// Execute on master server to ensure if we've just created a table that we get the correct result

	function table_exists($table)
{
// Execute on master server to ensure if we've just created a table that we get the correct result

		$query = $this->write_query("
SELECT `TABLE_NAME` FROM INFORMATION_SCHEMA.TABLES
WHERE `TABLE_TYPE` = 'BASE TABLE'
AND `TABLE_NAME` LIKE '{$this->table_prefix}$table'
");
$exists = $this->num_rows($query);

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




		if(version_compare($this->get_version(), '5.0.2', '>='))
{
$query = $this->query("SHOW FULL TABLES FROM `".$this->database."` WHERE table_type = 'BASE TABLE' AND `Tables_in_".$this->database."` = '{$this->table_prefix}$table'");
}
else
{
$query = $this->query("SHOW TABLES LIKE '{$this->table_prefix}$table'");
}

$exists = $this->num_rows($query);
if($exists > 0)
{
return true;
}
else
{
return false;
}

	}

/**

	}

/**

Zeile 722Zeile 742
		else
{
$shutdown_queries[] = $query;

		else
{
$shutdown_queries[] = $query;

		}

		}

	}

/**

	}

/**

Zeile 781Zeile 801
		global $mybb;

if(!is_array($array))

		global $mybb;

if(!is_array($array))

		{

		{

			return false;
}


			return false;
}


Zeile 795Zeile 815
				}

$array[$field] = $value;

				}

$array[$field] = $value;

			}

			}

			else
{
$array[$field] = $this->quote_val($value);

			else
{
$array[$field] = $this->quote_val($value);

Zeile 808Zeile 828
			INSERT
INTO {$this->table_prefix}{$table} (".$fields.")
VALUES (".$values.")

			INSERT
INTO {$this->table_prefix}{$table} (".$fields.")
VALUES (".$values.")

		");

		");

		return $this->insert_id();
}


		return $this->insert_id();
}


Zeile 820Zeile 840
	 * @return void
*/
function insert_query_multiple($table, $array)

	 * @return void
*/
function insert_query_multiple($table, $array)

	{
global $mybb;


	{
global $mybb;


		if(!is_array($array))
{
return;

		if(!is_array($array))
{
return;

Zeile 878Zeile 898
		if(!is_array($array))
{
return false;

		if(!is_array($array))
{
return false;

		}


		}


		$comma = "";
$query = "";
$quote = "'";

		$comma = "";
$query = "";
$quote = "'";





		if($no_quote == true)
{
$quote = "";

		if($no_quote == true)
{
$quote = "";

Zeile 892Zeile 912
		foreach($array as $field => $value)
{
if(isset($mybb->binary_fields[$table][$field]) && $mybb->binary_fields[$table][$field])

		foreach($array as $field => $value)
{
if(isset($mybb->binary_fields[$table][$field]) && $mybb->binary_fields[$table][$field])

			{

			{

				if($value[0] != 'X') // Not escaped?
{
$value = $this->escape_binary($value);
}

$query .= $comma."`".$field."`={$value}";

				if($value[0] != 'X') // Not escaped?
{
$value = $this->escape_binary($value);
}

$query .= $comma."`".$field."`={$value}";

			}

			}

			else
{
$quoted_value = $this->quote_val($value, $quote);

			else
{
$quoted_value = $this->quote_val($value, $quote);





				$query .= $comma."`".$field."`={$quoted_value}";
}
$comma = ', ';

				$query .= $comma."`".$field."`={$quoted_value}";
}
$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 928Zeile 948
	/**
* @param int|string $value
* @param string $quote

	/**
* @param int|string $value
* @param string $quote

	 *

	 *

	 * @return int|string
*/
private function quote_val($value, $quote="'")
{
if(is_int($value))

	 * @return int|string
*/
private function quote_val($value, $quote="'")
{
if(is_int($value))

		{

		{

			$quoted = $value;

			$quoted = $value;

		}

		}

		else
{
$quoted = $quote . $value . $quote;
}

return $quoted;

		else
{
$quoted = $quote . $value . $quote;
}

return $quoted;

	}

	}


/**
* Build a delete query.


/**
* Build a delete query.

Zeile 969Zeile 989

/**
* Escape a string according to the MySQL escape format.


/**
* Escape a string according to the MySQL escape format.

	 *
* @param string $string The string to be escaped.
* @return string The escaped string.
*/

	 *
* @param string $string The string to be escaped.
* @return string The escaped string.
*/

	function escape_string($string)
{
if($this->db_encoding == 'utf8')

	function escape_string($string)
{
if($this->db_encoding == 'utf8')

		{

		{

			$string = validate_utf8_string($string, false);

			$string = validate_utf8_string($string, false);

		}

		}

		elseif($this->db_encoding == 'utf8mb4')

		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);

			$string = validate_utf8_string($string);
}

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

		}

		}

		else
{
$string = addslashes($string);

		else
{
$string = addslashes($string);

Zeile 1002Zeile 1022
	 * @return boolean Returns true
*/
function free_result($query)

	 * @return boolean Returns true
*/
function free_result($query)

	{

	{

		mysqli_free_result($query);
return true; // Kept for compatibility reasons
}

		mysqli_free_result($query);
return true; // Kept for compatibility reasons
}

Zeile 1017Zeile 1037
	{
return $this->escape_string(str_replace(array('%', '_') , array('\\%' , '\\_') , $string));
}

	{
return $this->escape_string(str_replace(array('%', '_') , array('\\%' , '\\_') , $string));
}





	/**
* Gets the current version of MySQL.
*

	/**
* Gets the current version of MySQL.
*

Zeile 1026Zeile 1046
	function get_version()
{
if($this->version)

	function get_version()
{
if($this->version)

		{

		{

			return $this->version;

			return $this->version;

		}

		}





		$version = @mysqli_get_server_info($this->read_link);
if(!$version)
{
$query = $this->query("SELECT VERSION() as version");
$ver = $this->fetch_array($query);
$version = $ver['version'];
}

		$query = $this->query("SELECT VERSION() as version");
$ver = $this->fetch_array($query);
$version = $ver['version'];






if($version)
{


if($version)
{

Zeile 1272Zeile 1288
	 *
* @param string $table The table
* @param array $replacements The replacements

	 *
* @param string $table The table
* @param array $replacements The replacements

 
	 * @param string|array $default_field The default field(s)
* @param boolean $insert_id Whether or not to return an insert id. True by default

	 * @return mysqli_result|bool
*/

	 * @return mysqli_result|bool
*/

	function replace_query($table, $replacements=array())

	function replace_query($table, $replacements=array(), $default_field="", $insert_id=true)

	{
global $mybb;


	{
global $mybb;


Zeile 1438Zeile 1456
			'cp1251' => 'Windows Cyrillic',
'cp1256' => 'Windows Arabic',
'cp1257' => 'Windows Baltic',

			'cp1251' => 'Windows Cyrillic',
'cp1256' => 'Windows Arabic',
'cp1257' => 'Windows Baltic',

			'binary' => 'Binary pseudo charset',

 
			'geostd8' => 'GEOSTD8 Georgian',
'cp932' => 'SJIS for Windows Japanese',
'eucjpms' => 'UJIS for Windows Japanese',

			'geostd8' => 'GEOSTD8 Georgian',
'cp932' => 'SJIS for Windows Japanese',
'eucjpms' => 'UJIS for Windows Japanese',

Zeile 1487Zeile 1504
			'cp1251' => 'cp1251_general_ci',
'cp1256' => 'cp1256_general_ci',
'cp1257' => 'cp1257_general_ci',

			'cp1251' => 'cp1251_general_ci',
'cp1256' => 'cp1256_general_ci',
'cp1257' => 'cp1257_general_ci',

			'binary' => 'binary',

 
			'geostd8' => 'geostd8_general_ci',
'cp932' => 'cp932_japanese_ci',
'eucjpms' => 'eucjpms_japanese_ci',

			'geostd8' => 'geostd8_general_ci',
'cp932' => 'cp932_japanese_ci',
'eucjpms' => 'eucjpms_japanese_ci',