Vergleich inc/db_mysql.php - 1.8.7 - 1.8.33

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

	 * @var resource
*/
public $current_link;

 

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


/**
* The database name.


/**
* The database name.

Zeile 191Zeile 196
			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 485Zeile 490
		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 495Zeile 504

/**
* Moves internal row pointer to the next row


/**
* Moves internal row pointer to the next row

	 *
* @param resource $query The query ID.

	 *
* @param resource $query The query ID.

	 * @param int $row The pointer to move the row to.
* @return bool
*/

	 * @param int $row The pointer to move the row to.
* @return bool
*/

Zeile 514Zeile 523
	function num_rows($query)
{
return mysql_num_rows($query);

	function num_rows($query)
{
return mysql_num_rows($query);

	}

/**

	}

/**

	 * Return the last id number of inserted data.
*
* @return int The id number.

	 * Return the last id number of inserted data.
*
* @return int The id number.

Zeile 524Zeile 533
	function insert_id()
{
return mysql_insert_id($this->current_link);

	function insert_id()
{
return mysql_insert_id($this->current_link);

	}

/**

	}

/**

	 * Close the connection with the DBMS.
*
*/

	 * Close the connection with the DBMS.
*
*/

Zeile 536Zeile 545
		if($this->write_link)
{
@mysql_close($this->write_link);

		if($this->write_link)
{
@mysql_close($this->write_link);

		}

		}

	}

/**

	}

/**

Zeile 545Zeile 554
	 * @return int The error number of the current error.
*/
function error_number()

	 * @return int The error number of the current error.
*/
function error_number()

	{
if($this->current_link)

	{
if($this->current_link)

		{
return @mysql_errno($this->current_link);
}

		{
return @mysql_errno($this->current_link);
}

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

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

		}

		}

		else
{
return @mysql_error();

		else
{
return @mysql_error();

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

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

			}


			}


			return true;

			return true;

		}

		}

		else
{
return false;
}

		else
{
return false;
}

	}


	}


	/**
* Returns the number of affected rows in a query.
*
* @return int The number of affected rows.
*/
function affected_rows()

	/**
* Returns the number of affected rows in a query.
*
* @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.
*
* @param resource $query The query ID.
* @return int The number of fields.

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

	 */

	 */

	function num_fields($query)
{
return mysql_num_fields($query);

	function num_fields($query)
{
return mysql_num_fields($query);

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

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

	{

	{

		if($prefix)
{
if(version_compare($this->get_version(), '5.0.2', '>='))

		if($prefix)
{
if(version_compare($this->get_version(), '5.0.2', '>='))

Zeile 692Zeile 701
		{
$query = $this->query("SHOW TABLES LIKE '{$this->table_prefix}$table'");
}

		{
$query = $this->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.
*
* @param string $field The field name.

	 * Check if a field exists in a database.
*
* @param string $field The field name.

Zeile 720Zeile 729
		");
$exists = $this->num_rows($query);
if($exists > 0)

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

		{
return true;
}
else
{
return false;
}
}

/**

		{
return true;
}
else
{
return false;
}
}

/**

	 * Add a shutdown query.
*
* @param resource $query The query data.

	 * Add a shutdown query.
*
* @param resource $query The query data.

Zeile 770Zeile 779
		}

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

		}

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

		{

		{

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

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

Zeile 811Zeile 820
			if(isset($mybb->binary_fields[$table][$field]) && $mybb->binary_fields[$table][$field])
{
if($value[0] != 'X') // Not escaped?

			if(isset($mybb->binary_fields[$table][$field]) && $mybb->binary_fields[$table][$field])
{
if($value[0] != 'X') // Not escaped?

				{

				{

					$value = $this->escape_binary($value);
}

$array[$field] = $value;

					$value = $this->escape_binary($value);
}

$array[$field] = $value;

			}

			}

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

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

Zeile 831Zeile 840
			VALUES (".$values.")
");
return $this->insert_id();

			VALUES (".$values.")
");
return $this->insert_id();

	}

	}


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


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

Zeile 852Zeile 861
		// 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 891Zeile 900
	 * @param string $where An optional where clause for the query.
* @param string $limit An optional limit clause for the query.
* @param boolean $no_quote An option to quote incoming values of the array.

	 * @param string $where An optional where clause for the query.
* @param string $limit An optional limit clause for the query.
* @param boolean $no_quote An option to quote incoming values of the array.

	 * @return resource The query data.
*/

	 * @return resource The query data.
*/

	function update_query($table, $array, $where="", $limit="", $no_quote=false)
{
global $mybb;

	function update_query($table, $array, $where="", $limit="", $no_quote=false)
{
global $mybb;

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

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

		}

if(!empty($where))

		}

if(!empty($where))

		{
$query .= " WHERE $where";

		{
$query .= " WHERE $where";

		}

		}


if(!empty($limit))
{


if(!empty($limit))
{

Zeile 952Zeile 961
	 * @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 1013Zeile 1022
		}

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

		}

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

		{

		{

			$string = mysql_real_escape_string($string, $this->read_link);

			$string = mysql_real_escape_string($string, $this->read_link);

		}

		}

		else
{
$string = addslashes($string);
}
return $string;

		else
{
$string = addslashes($string);
}
return $string;

	}


	}


	/**
* Frees the resources of a MySQLi query.
*

	/**
* Frees the resources of a MySQLi query.
*

Zeile 1032Zeile 1041
	function free_result($query)
{
return mysql_free_result($query);

	function free_result($query)
{
return mysql_free_result($query);

	}


	}


	/**
* Escape a string used within a like command.

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

	 * @param string $string The string to be escaped.
* @return string The escaped string.
*/
function escape_string_like($string)

	{
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 1057Zeile 1066
			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)
{
$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.
*

	/**
* Optimizes a specific table.
*

Zeile 1085Zeile 1090

/**
* Analyzes a specific table.


/**
* Analyzes a specific table.

	 *

	 *

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

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

	 */

	 */

	function analyze_table($table)

	function analyze_table($table)

	{

	{

		$this->write_query("ANALYZE TABLE {$this->table_prefix}{$table}");

		$this->write_query("ANALYZE TABLE {$this->table_prefix}{$table}");

	}


	}


	/**
* Show the "create table" command for a specific table.
*

	/**
* Show the "create table" command for a specific table.
*

Zeile 1104Zeile 1109
		$query = $this->write_query("SHOW CREATE TABLE {$this->table_prefix}{$table}");
$structure = $this->fetch_array($query);
return $structure['Create Table'];

		$query = $this->write_query("SHOW CREATE TABLE {$this->table_prefix}{$table}");
$structure = $this->fetch_array($query);
return $structure['Create Table'];

	}


	}


	/**
* Show the "show fields from" command for a specific table.
*

	/**
* Show the "show fields from" command for a specific table.
*

Zeile 1125Zeile 1130

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


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

	 *

	 *

	 * @param string $table The name of the table.
* @param string $index Optionally specify the name of the index.
* @return boolean True or false if the table has a fulltext index or not.

	 * @param string $table The name of the table.
* @param string $index Optionally specify the name of the index.
* @return boolean True or false if the table has a fulltext index or not.

Zeile 1138Zeile 1143
			if(preg_match("#FULLTEXT KEY (`?)$index(`?)#i", $structure))
{
return true;

			if(preg_match("#FULLTEXT KEY (`?)$index(`?)#i", $structure))
{
return true;

			}

			}

			else
{
return false;
}
}
if(preg_match('#FULLTEXT KEY#i', $structure))

			else
{
return false;
}
}
if(preg_match('#FULLTEXT KEY#i', $structure))

		{

		{

			return true;
}
return false;

			return true;
}
return false;

Zeile 1203Zeile 1208
		}

if($index_exists)

		}

if($index_exists)

		{
return true;
}

		{
return true;
}


return false;
}


return false;
}

Zeile 1225Zeile 1230
			return true;
}
return false;

			return true;
}
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.

Zeile 1264Zeile 1269
	 * @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)
{

	{
if($table_prefix == false)
{

			$table_prefix = "";
}
else

			$table_prefix = "";
}
else

Zeile 1311Zeile 1316
	 *
* @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 1348Zeile 1355

/**
* 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 1367Zeile 1376
	 * @return resource
*/
function add_column($table, $column, $definition)

	 * @return resource
*/
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 $table The table

	 * @param string $column The column name

	 * @param string $column The column name

	 * @param string $new_definition the new column definition
* @return resource
*/
function modify_column($table, $column, $new_definition)
{
return $this->write_query("ALTER TABLE {$this->table_prefix}{$table} MODIFY {$column} {$new_definition}");
}






























	 * @param string $new_definition the new column 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)
{
$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}");
}


/**
* Renames a column


/**
* Renames a column

Zeile 1391Zeile 1431
	 * @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 1477Zeile 1547
			'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 1526Zeile 1595
			'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',