Vergleich inc/db_mysqli.php - 1.8.19 - 1.8.33

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

	 * @var mysqli
*/
public $current_link;

 

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


/**
* The database name.


/**
* The database name.

	 *
* @var string

	 *
* @var string

	 */
public $database;

	 */
public $database;





	/**
* Explanation of a query.

	/**
* Explanation of a query.

	 *
* @var string
*/

	 *
* @var string
*/

	public $explain;

/**

	public $explain;

/**

Zeile 93Zeile 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;


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

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





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

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

	 *

	 *

	 * @var boolean
*/
public $can_search = true;

	 * @var boolean
*/
public $can_search = true;


/**


/**

	 * The database encoding currently in use (if supported)
*
* @var string

	 * The database encoding currently in use (if supported)
*
* @var string

Zeile 135Zeile 140
	 * @var float
*/
public $query_time = 0;

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





	/**
* Stores previous run query type: 1 => write; 0 => read

	/**
* Stores previous run query type: 1 => write; 0 => read

	 *

	 *

	 * @var int

	 * @var int

	 */

	 */

	protected $last_query_type = 0;

/**

	protected $last_query_type = 0;

/**

Zeile 155Zeile 160
		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 190Zeile 195
			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 216Zeile 221
				if(strstr($single_connection['hostname'],':'))
{
list($hostname, $port) = explode(":", $single_connection['hostname'], 2);

				if(strstr($single_connection['hostname'],':'))
{
list($hostname, $port) = explode(":", $single_connection['hostname'], 2);

				}


				}


				if($port)
{
$this->$link = @$connect_function($persist.$hostname, $single_connection['username'], $single_connection['password'], "", $port);

				if($port)
{
$this->$link = @$connect_function($persist.$hostname, $single_connection['username'], $single_connection['password'], "", $port);

				}
else
{
$this->$link = @$connect_function($persist.$single_connection['hostname'], $single_connection['username'], $single_connection['password']);

				}
else
{
$this->$link = @$connect_function($persist.$single_connection['hostname'], $single_connection['username'], $single_connection['password']);

				}

$time_spent = get_execution_time();

				}

$time_spent = get_execution_time();

Zeile 232Zeile 237

// Successful connection? break down brother!
if($this->$link)


// Successful connection? break down brother!
if($this->$link)

				{

				{

					$this->connections[] = "[".strtoupper($type)."] {$single_connection['username']}@{$single_connection['hostname']} (Connected in ".format_time_duration($time_spent).")";
break;

					$this->connections[] = "[".strtoupper($type)."] {$single_connection['username']}@{$single_connection['hostname']} (Connected in ".format_time_duration($time_spent).")";
break;

				}
else
{

				}
else
{

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

Zeile 485Zeile 490
			$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 513Zeile 522

/**
* Return the last id number of inserted data.


/**
* Return the last id number of inserted data.

	 *

	 *

	 * @return int The id number.
*/
function insert_id()
{
$id = mysqli_insert_id($this->current_link);
return $id;

	 * @return int The id number.
*/
function insert_id()
{
$id = mysqli_insert_id($this->current_link);
return $id;

	}

/**

	}

/**

	 * Close the connection with the DBMS.
*
*/

	 * Close the connection with the DBMS.
*
*/

Zeile 532Zeile 541
		if($this->write_link)
{
@mysqli_close($this->write_link);

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

		}

		}

	}

/**

	}

/**

Zeile 541Zeile 550
	 * @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 mysqli_errno($this->current_link);
}

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

Zeile 562Zeile 571
		if($this->current_link)
{
return mysqli_error($this->current_link);

		if($this->current_link)
{
return mysqli_error($this->current_link);

		}
else
{

		}
else
{

			return mysqli_connect_error();
}
}

			return mysqli_connect_error();
}
}

Zeile 599Zeile 608
			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;
}
else

			return true;
}
else

Zeile 678Zeile 687
	 * @return boolean True when exists, false if not.
*/
function table_exists($table)

	 * @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
if(version_compare($this->get_version(), '5.0.2', '>='))

		// Execute on master server to ensure if we've just created a table that we get the correct result
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'");

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

		else
{

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

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

/**

			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 717Zeile 726
		$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 mysqli_result $query The query data.

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

Zeile 747Zeile 756

/**
* Performs a simple select query.


/**
* Performs a simple select query.

	 *

	 *

	 * @param string $table The table name to be queried.
* @param string $fields Comma delimetered list of fields to be selected.
* @param string $conditions SQL formatted list of conditions to be matched.

	 * @param string $table The table name to be queried.
* @param string $fields Comma delimetered list of fields to be selected.
* @param string $conditions SQL formatted list of conditions to be matched.

Zeile 761Zeile 770
		if($conditions != "")
{
$query .= " WHERE ".$conditions;

		if($conditions != "")
{
$query .= " WHERE ".$conditions;

		}

		}


if(isset($options['group_by']))
{
$query .= " GROUP BY ".$options['group_by'];


if(isset($options['group_by']))
{
$query .= " GROUP BY ".$options['group_by'];

		}


		}


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

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

Zeile 775Zeile 784
			{
$query .= " ".my_strtoupper($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']))

		{

		{

			$query .= " LIMIT ".$options['limit_start'].", ".$options['limit'];
}
else if(isset($options['limit']))

			$query .= " LIMIT ".$options['limit_start'].", ".$options['limit'];
}
else if(isset($options['limit']))

Zeile 787Zeile 796
		}

return $this->query($query);

		}

return $this->query($query);

	}


	}


	/**
* Build an insert query from an array.
*

	/**
* Build an insert query from an array.
*

Zeile 801Zeile 810
		global $mybb;

if(!is_array($array))

		global $mybb;

if(!is_array($array))

		{

		{

			return false;
}

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

			return false;
}

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

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

Zeile 828Zeile 837
			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 889Zeile 898
	 * @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 mysqli_result The query data.

	 * @return mysqli_result The query data.

	 */
function update_query($table, $array, $where="", $limit="", $no_quote=false)
{

	 */
function update_query($table, $array, $where="", $limit="", $no_quote=false)
{

Zeile 903Zeile 912
		$comma = "";
$query = "";
$quote = "'";

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





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

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

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

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

		{

		{

			if(isset($mybb->binary_fields[$table][$field]) && $mybb->binary_fields[$table][$field])

			if(isset($mybb->binary_fields[$table][$field]) && $mybb->binary_fields[$table][$field])

			{

			{

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

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

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

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

		}

if(!empty($where))
{

		}

if(!empty($where))
{

			$query .= " WHERE $where";
}


			$query .= " WHERE $where";
}


Zeile 989Zeile 998

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

	 */
function escape_string($string)
{

Zeile 1032Zeile 1041
	 *
* @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 1053Zeile 1062
		$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 1074Zeile 1083

/**
* Analyzes a specific table.


/**
* Analyzes a specific table.

	 *

	 *

	 * @param string $table The name of the table to be analyzed.
*/
function analyze_table($table)

	 * @param string $table The name of the table to be analyzed.
*/
function analyze_table($table)

Zeile 1094Zeile 1103
		$structure = $this->fetch_array($query);

return $structure['Create 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 1115Zeile 1124

/**
* 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 1128Zeile 1137
			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;
}





	/**
* Returns whether or not this database engine supports fulltext indexing.
*

	/**
* Returns whether or not this database engine supports fulltext indexing.
*

Zeile 1155Zeile 1164
		$status = $this->fetch_array($query);
$table_type = my_strtoupper($status['Engine']);
if(version_compare($version, '3.23.23', '>=') && ($table_type == 'MYISAM' || $table_type == 'ARIA'))

		$status = $this->fetch_array($query);
$table_type = my_strtoupper($status['Engine']);
if(version_compare($version, '3.23.23', '>=') && ($table_type == 'MYISAM' || $table_type == 'ARIA'))

		{

		{

			return true;
}
elseif(version_compare($version, '5.6', '>=') && $table_type == 'INNODB')

			return true;
}
elseif(version_compare($version, '5.6', '>=') && $table_type == 'INNODB')

Zeile 1176Zeile 1185
		$version = $this->get_version();
$supports_fulltext = $this->supports_fulltext($table);
if(version_compare($version, '4.0.1', '>=') && $supports_fulltext == true)

		$version = $this->get_version();
$supports_fulltext = $this->supports_fulltext($table);
if(version_compare($version, '4.0.1', '>=') && $supports_fulltext == true)

		{

		{

			return true;
}
return false;

			return true;
}
return false;

Zeile 1216Zeile 1225
	 * @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.

	 */

	 */

	function create_fulltext_index($table, $column, $name="")
{
$this->write_query("ALTER TABLE {$this->table_prefix}$table ADD FULLTEXT $name ($column)");

	function create_fulltext_index($table, $column, $name="")
{
$this->write_query("ALTER TABLE {$this->table_prefix}$table ADD FULLTEXT $name ($column)");

Zeile 1318Zeile 1327
		}

if(empty($replacements))

		}

if(empty($replacements))

		{

		{

			 return false;
}


			 return false;
}


Zeile 1337Zeile 1346
		$column = trim($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 1360Zeile 1369
	 * @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)
{

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

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


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



























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 1376Zeile 1412
	 * @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)

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


	{
$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}");


























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

	}

/**

	}

/**