Vergleich inc/db_mysql.php - 1.8.6 - 1.8.19

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

/**

	public $current_link;

/**

	 * Explanation of a query.








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

/**
* Explanation of a query.

	 *
* @var string
*/

	 *
* @var string
*/

Zeile 82Zeile 89

/**
* The current version of MySQL.


/**
* The current version of MySQL.

	 *
* @var string

	 *
* @var string

	 */
public $version;


	 */
public $version;


Zeile 93Zeile 100
	 * @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 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 232Zeile 239
		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)
{
$this->error("[WRITE] Unable to connect to MySQL server");
return false;

		// No write?
else if(!$this->write_link)
{
$this->error("[WRITE] Unable to connect to MySQL server");
return false;

		}


		}


		// Select databases
if(!$this->select_db($config['database']))
{
return -1;
}

		// Select databases
if(!$this->select_db($config['database']))
{
return -1;
}





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

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

Zeile 259Zeile 266
	 */
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 553Zeile 562
	 * @return string The explanation for the current error.
*/
function error_string()

	 * @return string The explanation for the current error.
*/
function error_string()

	{

	{

		if($this->current_link)
{
return @mysql_error($this->current_link);

		if($this->current_link)
{
return @mysql_error($this->current_link);

Zeile 573Zeile 582
	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 610Zeile 619
	 * @return int The number of affected rows.
*/
function affected_rows()

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

	{
return mysql_affected_rows($this->current_link);
}


	{
return mysql_affected_rows($this->current_link);
}


	/**
* Return the number of fields.

	/**
* Return the number of fields.

	 *

	 *

	 * @param resource $query The query ID.
* @return int The number of fields.
*/

	 * @param resource $query The query ID.
* @return int The number of fields.
*/

Zeile 633Zeile 642
	 * @return array The table list.
*/
function list_tables($database, $prefix='')

	 * @return array The table list.
*/
function list_tables($database, $prefix='')

	{

	{

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

		}

$tables = array();

Zeile 655Zeile 671
		{
$tables[] = $table;
}

		{
$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.

	 *
* @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

	 * @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

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





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

		$exists = $this->num_rows($query);
if($exists > 0)
{

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

		else
{
$shutdown_queries[] = $query;

		}

		}

	}
/**
* Performs a simple select query.

	}
/**
* Performs a simple select query.

Zeile 778Zeile 798
	 * @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 841
	 * @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 903
		}

$comma = "";

		}

$comma = "";

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


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


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

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

Zeile 905Zeile 925
			else
{
$quoted_val = $this->quote_val($value, $quote);

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





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

				$query .= $comma."`".$field."`={$quoted_val}";
}
$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 924Zeile 944
		return $this->write_query("
UPDATE {$this->table_prefix}$table
SET $query

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

		");

		");

	}

/**

	}

/**

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

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

		{

		{

			$quoted = $value;

			$quoted = $value;

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


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


		return $quoted;
}


		return $quoted;
}


Zeile 961Zeile 981
		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 1019Zeile 1039
	 *
* @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_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 1057
			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 1225

/**
* 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 $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 $column Name of the column to be indexed.
* @param string $name The index name, optional.
*/

Zeile 1244Zeile 1260
	 * @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)

		{

		{

			$this->write_query('DROP TABLE IF EXISTS '.$table_prefix.$table);
}
else

			$this->write_query('DROP TABLE IF EXISTS '.$table_prefix.$table);
}
else

Zeile 1270Zeile 1286
	 * @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 resource

	 * @return resource

	 */
function rename_table($old_table, $new_table, $table_prefix=true)
{

	 */
function rename_table($old_table, $new_table, $table_prefix=true)
{

Zeile 1291Zeile 1307
	 *
* @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 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 1328Zeile 1346

/**
* 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 1368
	 */
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}");

	}

/**
* Modifies a column

	}

/**
* Modifies a column

	 *

	 *

	 * @param string $table The table
* @param string $column The column name

	 * @param string $table The table
* @param string $column The column name

	 * @param string $new_definition the new column definition
* @return resource
*/

	 * @param string $new_definition the new column definition
* @return resource
*/

	function modify_column($table, $column, $new_definition)
{

	function modify_column($table, $column, $new_definition)
{

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



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

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

	}

/**

	}

/**

Zeile 1375Zeile 1399
	 */
function rename_column($table, $old_column, $new_column, $new_definition)
{

	 */
function rename_column($table, $old_column, $new_column, $new_definition)
{

		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, '`');

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

	}

/**

	}

/**

Zeile 1457Zeile 1484
			'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 1532
			'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',