Vergleich inc/db_mysql.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
*/








	 * @var string
*/
public $database;

/**
* Explanation of a query.
*
* @var string
*/

	public $explain;

/**

	public $explain;

/**

Zeile 86Zeile 98
	 * @var string
*/
public $version;

	 * @var string
*/
public $version;


/**


/**

	 * The current table type in use (myisam/innodb)

	 * The current table type in use (myisam/innodb)

	 *
* @var string

	 *
* @var string

	 */
public $table_type = "myisam";

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

	 */
public $table_type = "myisam";

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

	 *
* @var string
*/

	 *
* @var string
*/

	public $table_prefix;

	public $table_prefix;


/**


/**

	 * The extension used to run the SQL database
*
* @var string

	 * The extension used to run the SQL database
*
* @var string

Zeile 110Zeile 122

/**
* Weather or not this engine can use the search functionality


/**
* Weather or not this engine can use the search functionality

	 *

	 *

	 * @var boolean

	 * @var boolean

	 */

	 */

	public $can_search = true;

	public $can_search = true;


/**


/**

	 * The database encoding currently in use (if supported)
*
* @var string
*/
public $db_encoding = "utf8";

	 * The database encoding currently in use (if supported)
*
* @var string
*/
public $db_encoding = "utf8";


/**


/**

	 * The time spent performing queries

	 * The time spent performing queries

	 *

	 *

	 * @var float
*/
public $query_time = 0;

	 * @var float
*/
public $query_time = 0;

Zeile 133Zeile 145
	 * 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 171Zeile 183
			}
}


			}
}


		$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 184Zeile 199
			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 259Zeile 274
	 */
function select_db($database)
{

	 */
function select_db($database)
{

 
		$this->database = $database;


		$this->current_link = &$this->read_link;
$read_success = @mysql_select_db($database, $this->read_link) or $this->error("[READ] Unable to select database", $this->read_link);
if($this->write_link)

		$this->current_link = &$this->read_link;
$read_success = @mysql_select_db($database, $this->read_link) or $this->error("[READ] Unable to select database", $this->read_link);
if($this->write_link)

Zeile 476Zeile 493
		if($row === false)
{
$array = $this->fetch_array($query);

		if($row === false)
{
$array = $this->fetch_array($query);

			return $array[$field];





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

		}
else
{

		}
else
{

Zeile 636Zeile 657
	{
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)."%'
");




			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

		}
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'");
}
else
{
$query = $this->query("SHOW TABLES FROM `$database`");
}

		}

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

		}

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

		}


		}


		return $tables;
}

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

		return $tables;
}

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

	 *
* @param string $table The table name.
* @return boolean True when exists, false if not.
*/

	 *
* @param string $table The table name.
* @return boolean True when exists, false if not.
*/

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





		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;

		else
{
return false;

Zeile 686Zeile 718

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


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

	 *

	 *

	 * @param string $field The field name.
* @param string $table The table name.
* @return boolean True when exists, false if not.

	 * @param string $field The field name.
* @param string $table The table name.
* @return boolean True when exists, false if not.

Zeile 706Zeile 738
		else
{
return false;

		else
{
return false;

		}

		}

	}

/**

	}

/**

Zeile 725Zeile 757
		else
{
$shutdown_queries[] = $query;

		else
{
$shutdown_queries[] = $query;

		}

		}

	}
/**
* Performs a simple select query.

	}
/**
* Performs a simple select query.

Zeile 778Zeile 810
	 * @return int The insert ID if available
*/
function insert_query($table, $array)

	 * @return int The insert ID if available
*/
function insert_query($table, $array)

	{
global $mybb;

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

	{
global $mybb;

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


foreach($array as $field => $value)
{


foreach($array as $field => $value)
{

Zeile 821Zeile 853
	 * @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 883Zeile 915
		}

$comma = "";

		}

$comma = "";

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


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


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

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

Zeile 938Zeile 970
		if(is_int($value))
{
$quoted = $value;

		if(is_int($value))
{
$quoted = $value;

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

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


return $quoted;
}


return $quoted;
}

Zeile 961Zeile 993
		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 977Zeile 1009

/**
* 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')

Zeile 988Zeile 1020
			$string = validate_utf8_string($string, false);
}
elseif($this->db_encoding == 'utf8mb4')

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

		{

		{

			$string = validate_utf8_string($string);

			$string = validate_utf8_string($string);

		}

		}


if(function_exists("mysql_real_escape_string") && $this->read_link)
{


if(function_exists("mysql_real_escape_string") && $this->read_link)
{

Zeile 999Zeile 1031
		else
{
$string = addslashes($string);

		else
{
$string = addslashes($string);

		}

		}

		return $string;
}


		return $string;
}


Zeile 1022Zeile 1054
	 */
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 1037Zeile 1069
			return $this->version;
}


			return $this->version;
}


		$version = @mysql_get_server_info();
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 1209Zeile 1237

/**
* 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 1229Zeile 1257
	 * @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 1244Zeile 1272
	 * @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

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

		{
$table_prefix = $this->table_prefix;
}

		{
$table_prefix = $this->table_prefix;
}

Zeile 1288Zeile 1316

/**
* Replace contents of table with values


/**
* Replace contents of table with values

	 *
* @param string $table The table

	 *
* @param string $table The table

	 * @param array $replacements The replacements

	 * @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 resource|bool
*/

	 * @return resource|bool
*/

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

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

	{
global $mybb;


	{
global $mybb;


Zeile 1309Zeile 1339
				}

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

				}

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

			}
else

			}
else

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

$comma = ',';

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

$comma = ',';

		}

		}


if(empty($replacements))
{


if(empty($replacements))
{

Zeile 1328Zeile 1358

/**
* Drops a column


/**
* Drops a column

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

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

	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 1348Zeile 1380
	 */
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 1357Zeile 1391
	 * @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 resource
*/
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 1371Zeile 1434
	 * @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 resource



	 * @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 1457Zeile 1550
			'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 1506Zeile 1598
			'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',