Vergleich inc/db_mysqli.php - 1.8.6 - 1.8.37

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 74Zeile 74
	public $current_link;

/**

	public $current_link;

/**

	 * Explanation of a query.













	 * @var array
*/
public $connections = array();

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

/**
* Explanation of a query.

	 *
* @var string
*/

	 *
* @var string
*/

Zeile 82Zeile 94

/**
* The current version of MySQL.


/**
* The current version of MySQL.

	 *
* @var string

	 *
* @var string

	 */
public $version;


	 */
public $version;


Zeile 93Zeile 105
	 * @var string
*/
public $table_type = "myisam";

	 * @var string
*/
public $table_type = "myisam";





	/**
* The table prefix used for simple select, update, insert and delete queries
*

	/**
* The table prefix used for simple select, update, insert and delete queries
*

Zeile 170Zeile 182
			}
}


			}
}


		$this->db_encoding = $config['encoding'];




		if(isset($config['encoding']))
{
$this->db_encoding = $config['encoding'];
}


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


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

Zeile 183Zeile 198
			if(array_key_exists('hostname', $connections[$type]))
{
$details = $connections[$type];

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

				unset($connections);

				unset($connections[$type]);

				$connections[$type][] = $details;
}


				$connections[$type][] = $details;
}


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

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

				}

				}

			}
}


			}
}


Zeile 246Zeile 261
		if(!$this->read_link)
{
$this->error("[READ] Unable to connect to MySQL server");

		if(!$this->read_link)
{
$this->error("[READ] Unable to connect to MySQL server");

			return false;
}

			return false;
}

		// No write?
else if(!$this->write_link)
{

		// No write?
else if(!$this->write_link)
{

Zeile 273Zeile 288
	 */
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)
{

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

Zeile 476Zeile 493
			$this->data_seek($query, $row);
}
$array = $this->fetch_array($query);

			$this->data_seek($query, $row);
}
$array = $this->fetch_array($query);

		return $array[$field];





		if($array !== null)
{
return $array[$field];
}
return null;

	}

/**

	}

/**

Zeile 485Zeile 506
	 * @param mysqli_result $query The query ID.
* @param int $row The pointer to move the row to.
* @return bool

	 * @param mysqli_result $query The query ID.
* @param int $row The pointer to move the row to.
* @return bool

	 */

	 */

	function data_seek($query, $row)
{
return mysqli_data_seek($query, $row);

	function data_seek($query, $row)
{
return mysqli_data_seek($query, $row);

Zeile 511Zeile 532
	{
$id = mysqli_insert_id($this->current_link);
return $id;

	{
$id = mysqli_insert_id($this->current_link);
return $id;

	}


	}


	/**
* Close the connection with the DBMS.
*

	/**
* Close the connection with the DBMS.
*

Zeile 521Zeile 542
	{
@mysqli_close($this->read_link);
if($this->write_link)

	{
@mysqli_close($this->read_link);
if($this->write_link)

		{

		{

			@mysqli_close($this->write_link);
}
}

			@mysqli_close($this->write_link);
}
}

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

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

	 */

	 */

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

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

Zeile 567Zeile 588
	 * @return bool Whether error reporting is enabled or not
*/
function error($string="")

	 * @return bool Whether error reporting is enabled or not
*/
function error($string="")

	{

	{

		if($this->error_reporting)
{
if(class_exists("errorHandler"))

		if($this->error_reporting)
{
if(class_exists("errorHandler"))

Zeile 586Zeile 607
					"query" => $string
);
$error_handler->error(MYBB_SQL, $error);

					"query" => $string
);
$error_handler->error(MYBB_SQL, $error);

			}
else

			}
else

			{
trigger_error("<strong>[SQL] [".$this->error_number()."] ".$this->error_string()."</strong><br />{$string}", E_USER_ERROR);
}

			{
trigger_error("<strong>[SQL] [".$this->error_number()."] ".$this->error_string()."</strong><br />{$string}", E_USER_ERROR);
}

Zeile 606Zeile 627
	 * @return int The number of affected rows.
*/
function affected_rows()

	 * @return int The number of affected rows.
*/
function affected_rows()

	{

	{

		return mysqli_affected_rows($this->current_link);

		return mysqli_affected_rows($this->current_link);

	}


	}


	/**
* Return the number of fields.
*

	/**
* Return the number of fields.
*

Zeile 626Zeile 647
	 *
* @param string $database The database name.
* @param string $prefix Prefix of the table (optional)

	 *
* @param string $database The database name.
* @param string $prefix Prefix of the table (optional)

	 * @return array The table list.

	 * @return array The table list.

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

	 */
function list_tables($database, $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 692
	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 697Zeile 729
		$exists = $this->num_rows($query);

if($exists > 0)

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

if($exists > 0)

		{

		{

			return true;
}
else

			return true;
}
else

Zeile 716Zeile 748
	{
global $shutdown_queries;
if($name)

	{
global $shutdown_queries;
if($name)

		{

		{

			$shutdown_queries[$name] = $query;
}
else

			$shutdown_queries[$name] = $query;
}
else

Zeile 735Zeile 767
	 * @return mysqli_result The query data.
*/
function simple_select($table, $fields="*", $conditions="", $options=array())

	 * @return mysqli_result The query data.
*/
function simple_select($table, $fields="*", $conditions="", $options=array())

	{

	{

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

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





		if($conditions != "")

		if($conditions != "")

		{

		{

			$query .= " WHERE ".$conditions;

			$query .= " WHERE ".$conditions;

		}


		}


		if(isset($options['group_by']))

		if(isset($options['group_by']))

		{

		{

			$query .= " GROUP BY ".$options['group_by'];
}


			$query .= " GROUP BY ".$options['group_by'];
}


Zeile 754Zeile 786
			if(isset($options['order_dir']))
{
$query .= " ".my_strtoupper($options['order_dir']);

			if(isset($options['order_dir']))
{
$query .= " ".my_strtoupper($options['order_dir']);

			}

			}

		}

if(isset($options['limit_start']) && isset($options['limit']))

		}

if(isset($options['limit_start']) && isset($options['limit']))

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

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

				}


				}


				$array[$field] = $value;
}
else

				$array[$field] = $value;
}
else

Zeile 872Zeile 904
	 * @return mysqli_result The query data.
*/
function update_query($table, $array, $where="", $limit="", $no_quote=false)

	 * @return mysqli_result The query data.
*/
function update_query($table, $array, $where="", $limit="", $no_quote=false)

	{
global $mybb;

	{
global $mybb;


if(!is_array($array))
{


if(!is_array($array))
{

Zeile 907Zeile 939
				$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";
}





		return $this->write_query("
UPDATE {$this->table_prefix}$table
SET $query

		return $this->write_query("
UPDATE {$this->table_prefix}$table
SET $query

Zeile 930Zeile 962
	 * @param string $quote
*
* @return int|string

	 * @param string $quote
*
* @return int|string

	 */

	 */

	private function quote_val($value, $quote="'")
{
if(is_int($value))

	private function quote_val($value, $quote="'")
{
if(is_int($value))

Zeile 1005Zeile 1037
	{
mysqli_free_result($query);
return true; // Kept for compatibility reasons

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

	}

/**

	}

/**

	 * Escape a string used within a like command.
*
* @param string $string The string to be escaped.
* @return string The escaped string.

	 * Escape a string used within a like command.
*
* @param string $string The string to be escaped.
* @return string The escaped string.

	 */

	 */

	function escape_string_like($string)
{

	function escape_string_like($string)
{

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

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

	}

/**

	}

/**

Zeile 1028Zeile 1060
		if($this->version)
{
return $this->version;

		if($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)
{
$version = explode(".", $version, 3);
$this->version = (int)$version[0].".".(int)$version[1].".".(int)$version[2];
}
return $this->version;

		if($version)
{
$version = explode(".", $version, 3);
$this->version = (int)$version[0].".".(int)$version[1].".".(int)$version[2];
}
return $this->version;

	}

/**

	}

/**

	 * Optimizes a specific table.
*
* @param string $table The name of the table to be optimized.

	 * Optimizes a specific table.
*
* @param string $table The name of the table to be optimized.

Zeile 1054Zeile 1082
	function optimize_table($table)
{
$this->write_query("OPTIMIZE TABLE ".$this->table_prefix.$table."");

	function optimize_table($table)
{
$this->write_query("OPTIMIZE TABLE ".$this->table_prefix.$table."");

	}

/**

	}

/**

	 * Analyzes a specific table.
*
* @param string $table The name of the table to be analyzed.

	 * Analyzes a specific table.
*
* @param string $table The name of the table to be analyzed.

Zeile 1076Zeile 1104
	{
$query = $this->write_query("SHOW CREATE TABLE ".$this->table_prefix.$table."");
$structure = $this->fetch_array($query);

	{
$query = $this->write_query("SHOW CREATE TABLE ".$this->table_prefix.$table."");
$structure = $this->fetch_array($query);





		return $structure['Create Table'];
}


		return $structure['Create Table'];
}


Zeile 1095Zeile 1123
			$field_info[] = $field;
}
return $field_info;

			$field_info[] = $field;
}
return $field_info;

	}

	}


/**
* Returns whether or not the table contains a fulltext index.


/**
* Returns whether or not the table contains a fulltext index.

Zeile 1154Zeile 1182
	 *
* @param string $table The table to be checked.
* @return boolean True or false if supported or not.

	 *
* @param string $table The table to be checked.
* @return boolean True or false if supported or not.

	 */

	 */

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

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

Zeile 1192Zeile 1220
		}

return false;

		}

return false;

	}


	}


	/**
* Creates a fulltext index on the specified column in the specified table with optional index name.

	/**
* Creates a fulltext index on the specified column in the specified table with optional index name.

	 *

	 *

	 * @param string $table The name of the table.
* @param string $column Name of the column to be indexed.
* @param string $name The index name, optional.

	 * @param string $table The name of the table.
* @param string $column Name of the column to be indexed.
* @param string $name The index name, optional.

Zeile 1213Zeile 1241
	 * @param string $name The name of the index.
*/
function drop_index($table, $name)

	 * @param string $name The name of the index.
*/
function drop_index($table, $name)

	{

	{

		$this->write_query("ALTER TABLE {$this->table_prefix}$table DROP INDEX $name");
}


		$this->write_query("ALTER TABLE {$this->table_prefix}$table DROP INDEX $name");
}


Zeile 1225Zeile 1253
	 * @param boolean $table_prefix use table prefix
*/
function drop_table($table, $hard=false, $table_prefix=true)

	 * @param boolean $table_prefix use table prefix
*/
function drop_table($table, $hard=false, $table_prefix=true)

	{
if($table_prefix == false)
{
$table_prefix = "";
}
else
{
$table_prefix = $this->table_prefix;

	{
if($table_prefix == false)
{
$table_prefix = "";
}
else
{
$table_prefix = $this->table_prefix;

		}

if($hard == false)

		}

if($hard == false)

Zeile 1251Zeile 1279
	 * @param string $old_table The old table name
* @param string $new_table the new table name
* @param boolean $table_prefix use table prefix

	 * @param string $old_table The old table name
* @param string $new_table the new table name
* @param boolean $table_prefix use table prefix

	 * @return mysqli_result
*/

	 * @return mysqli_result
*/

	function rename_table($old_table, $new_table, $table_prefix=true)
{
if($table_prefix == false)

	function rename_table($old_table, $new_table, $table_prefix=true)
{
if($table_prefix == false)

Zeile 1272Zeile 1300
	 *
* @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 1290Zeile 1320
				}

$values .= $comma."`".$column."`=".$value;

				}

$values .= $comma."`".$column."`=".$value;

			}
else
{

			}
else
{

				$values .= $comma."`".$column."`=".$this->quote_val($value);
}

				$values .= $comma."`".$column."`=".$this->quote_val($value);
}





			$comma = ',';

			$comma = ',';

		}

		}


if(empty($replacements))
{


if(empty($replacements))
{

Zeile 1309Zeile 1339

/**
* Drops a column


/**
* Drops a column

	 *
* @param string $table The table
* @param string $column The column name
* @return mysqli_result
*/

	 *
* @param string $table The table
* @param string $column The column name
* @return mysqli_result
*/

	function drop_column($table, $column)

	function drop_column($table, $column)

	{
return $this->write_query("ALTER TABLE {$this->table_prefix}{$table} DROP {$column}");
}



	{
$column = trim($column, '`');

return $this->write_query("ALTER TABLE {$this->table_prefix}{$table} DROP `{$column}`");
}


/**
* Adds a column


/**
* Adds a column

Zeile 1329Zeile 1361
	 */
function add_column($table, $column, $definition)
{

	 */
function add_column($table, $column, $definition)
{

		return $this->write_query("ALTER TABLE {$this->table_prefix}{$table} ADD {$column} {$definition}");



		$column = trim($column, '`');

return $this->write_query("ALTER TABLE {$this->table_prefix}{$table} ADD `{$column}` {$definition}");

	}

/**

	}

/**

Zeile 1338Zeile 1372
	 * @param string $table The table
* @param string $column The column name
* @param string $new_definition the new column definition

	 * @param string $table The table
* @param string $column The column name
* @param string $new_definition the new column definition

	 * @return mysqli_result
*/
function modify_column($table, $column, $new_definition)



	 * @param boolean|string $new_not_null Whether to "drop" or "set" the NOT NULL attribute (no change if false)
* @param boolean|string $new_default_value The new default value, or false to drop the attribute
* @return bool Returns true if all queries are executed successfully or false if one of them failed
*/
function modify_column($table, $column, $new_definition, $new_not_null=false, $new_default_value=false)

	{

	{

		return $this->write_query("ALTER TABLE {$this->table_prefix}{$table} MODIFY {$column} {$new_definition}");




























		$column = trim($column, '`');

if($new_not_null !== false)
{
if(strtolower($new_not_null) == "set")
{
$not_null = "NOT NULL";
}
else
{
$not_null = "NULL";
}
}
else
{
$not_null = '';
}

if($new_default_value !== false)
{
$default = "DEFAULT ".$new_default_value;
}
else
{
$default = '';
}

return (bool)$this->write_query("ALTER TABLE {$this->table_prefix}{$table} MODIFY `{$column}` {$new_definition} {$not_null} {$default}");

	}

/**

	}

/**

Zeile 1352Zeile 1415
	 * @param string $old_column The old column name
* @param string $new_column the new column name
* @param string $new_definition the new column definition

	 * @param string $old_column The old column name
* @param string $new_column the new column name
* @param string $new_definition the new column definition

	 * @return mysqli_result



	 * @param boolean|string $new_not_null Whether to "drop" or "set" the NOT NULL attribute (no change if false)
* @param boolean|string $new_default_value The new default value, or false to drop the attribute
* @return bool Returns true if all queries are executed successfully

	 */

	 */

	function rename_column($table, $old_column, $new_column, $new_definition)

	function rename_column($table, $old_column, $new_column, $new_definition, $new_not_null=false, $new_default_value=false)

	{

	{

		return $this->write_query("ALTER TABLE {$this->table_prefix}{$table} CHANGE {$old_column} {$new_column} {$new_definition}");





























		$old_column = trim($old_column, '`');
$new_column = trim($new_column, '`');

if($new_not_null !== false)
{
if(strtolower($new_not_null) == "set")
{
$not_null = "NOT NULL";
}
else
{
$not_null = "NULL";
}
}
else
{
$not_null = '';
}

if($new_default_value !== false)
{
$default = "DEFAULT ".$new_default_value;
}
else
{
$default = '';
}

return (bool)$this->write_query("ALTER TABLE {$this->table_prefix}{$table} CHANGE `{$old_column}` `{$new_column}` {$new_definition} {$not_null} {$default}");

	}

/**

	}

/**

Zeile 1438Zeile 1531
			'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 1579
			'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',