Vergleich inc/db_mysql.php - 1.8.18 - 1.8.34

  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.

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

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

	 *
* @var string
*/

	 *
* @var string
*/

	public $table_prefix;

/**

	public $table_prefix;

/**

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

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


/**


/**

	 * Weather or not this engine can use the search functionality
*
* @var boolean

	 * Weather or not this engine can use the search functionality
*
* @var boolean

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 156Zeile 161
		if(array_key_exists('hostname', $config))
{
$connections['read'][] = $config;

		if(array_key_exists('hostname', $config))
{
$connections['read'][] = $config;

		}

		}

		// Connecting to more than one server
else
{

		// Connecting to more than one server
else
{

Zeile 170Zeile 175
						$connections['read'][] = $settings;
}
}

						$connections['read'][] = $settings;
}
}

			}

			}

			// Specified both read & write servers
else
{
$connections = $config;

			// Specified both read & write servers
else
{
$connections = $config;

			}
}

$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 191Zeile 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 239Zeile 247
		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 485Zeile 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 495Zeile 507

/**
* 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 507Zeile 519

/**
* Return the number of rows resulting from a query.


/**
* Return the number of rows resulting from a query.

	 *

	 *

	 * @param resource $query The query ID.
* @return int The number of rows in the result.
*/

	 * @param resource $query The query ID.
* @return int The number of rows in the result.
*/

Zeile 518Zeile 530

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


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

	 *

	 *

	 * @return int The id number.
*/
function insert_id()

	 * @return int The id number.
*/
function insert_id()

Zeile 528Zeile 540

/**
* Close the connection with the DBMS.


/**
* Close the connection with the DBMS.

	 *

	 *

	 */
function close()
{

	 */
function close()
{

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

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

		}
}

/**

		}
}

/**

	 * Return an error number.
*
* @return int The error number of the current error.

	 * Return an error number.
*
* @return int The error number of the current error.

Zeile 549Zeile 561
		if($this->current_link)
{
return @mysql_errno($this->current_link);

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

		}
else

		}
else

		{
return @mysql_errno();
}

		{
return @mysql_errno();
}

Zeile 570Zeile 582
		else
{
return @mysql_error();

		else
{
return @mysql_error();

		}
}

		}
}


/**
* Output a database error.


/**
* Output a database error.

Zeile 592Zeile 604
					require_once MYBB_ROOT."inc/class_error.php";
$error_handler = new errorHandler();
}

					require_once MYBB_ROOT."inc/class_error.php";
$error_handler = new errorHandler();
}





				$error = array(
"error_no" => $this->error_number(),
"error" => $this->error_string(),

				$error = array(
"error_no" => $this->error_number(),
"error" => $this->error_string(),

Zeile 603Zeile 615
			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 false;
}
}

/**

			}

return true;
}
else
{
return false;
}
}

/**

	 * Returns the number of affected rows in a query.
*
* @return int The number of affected rows.

	 * Returns the number of affected rows in a query.
*
* @return int The number of affected rows.

Zeile 632Zeile 644
	function num_fields($query)
{
return mysql_num_fields($query);

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

	}


	}


	/**
* Lists all tables in the database.
*

	/**
* Lists all tables in the database.
*

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

		if($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)."%'");

				$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

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

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

				$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 = array();
while(list($table) = mysql_fetch_array($query))
{

Zeile 673Zeile 685
		}

return $tables;

		}

return $tables;

	}

/**

	}

/**

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

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

Zeile 691Zeile 703
		else
{
$query = $this->query("SHOW TABLES LIKE '{$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)
{

			return true;
}
else

			return true;
}
else

Zeile 736Zeile 748
	 * @param string $name An optional name for the query.
*/
function shutdown_query($query, $name="")

	 * @param string $name An optional name for the query.
*/
function shutdown_query($query, $name="")

	{

	{

		global $shutdown_queries;
if($name)
{

		global $shutdown_queries;
if($name)
{

Zeile 775Zeile 787
			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 900Zeile 912
		if(!is_array($array))
{
return false;

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

		}


		}


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

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

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





	/**
* Build a delete query.
*

	/**
* Build a delete query.
*

Zeile 984Zeile 996
		}

if(!empty($limit))

		}

if(!empty($limit))

		{

		{

			$query .= " LIMIT $limit";
}


			$query .= " LIMIT $limit";
}


Zeile 1025Zeile 1037

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


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

	 *

	 *

	 * @param resource $query The query to destroy.
* @return boolean Returns true on success, false on faliure
*/

	 * @param resource $query The query to destroy.
* @return boolean Returns true on success, false on faliure
*/

Zeile 1042Zeile 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 1067Zeile 1079
			$this->version = (int)$version[0].".".(int)$version[1].".".(int)$version[2];
}
return $this->version;

			$this->version = (int)$version[0].".".(int)$version[1].".".(int)$version[2];
}
return $this->version;

	}

	}


/**
* Optimizes a specific table.


/**
* Optimizes a specific table.

Zeile 1075Zeile 1087
	 * @param string $table The name of the table to be optimized.
*/
function optimize_table($table)

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

	{

	{

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

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

	}

	}


/**
* Analyzes a specific table.


/**
* Analyzes a specific table.

Zeile 1087Zeile 1099
	function analyze_table($table)
{
$this->write_query("ANALYZE TABLE {$this->table_prefix}{$table}");

	function analyze_table($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.

	 *

	 *

	 * @param string $table The name of the table.
* @return string The MySQL command to create the specified table.

	 * @param string $table The name of the table.
* @return string The MySQL command to create the specified table.

	 */

	 */

	function show_create_table($table)
{
$query = $this->write_query("SHOW CREATE TABLE {$this->table_prefix}{$table}");

	function show_create_table($table)
{
$query = $this->write_query("SHOW CREATE TABLE {$this->table_prefix}{$table}");

Zeile 1107Zeile 1119
	 *
* @param string $table The name of the table.
* @return array Field info for that table

	 *
* @param string $table The name of the table.
* @return array Field info for that table

	 */

	 */

	function show_fields_from($table)
{
$query = $this->write_query("SHOW FIELDS FROM {$this->table_prefix}{$table}");

	function show_fields_from($table)
{
$query = $this->write_query("SHOW FIELDS FROM {$this->table_prefix}{$table}");

Zeile 1168Zeile 1180
			$table_type = my_strtoupper($status['Type']);
}
if(version_compare($version, '3.23.23', '>=') && ($table_type == 'MYISAM' || $table_type == 'ARIA'))

			$table_type = my_strtoupper($status['Type']);
}
if(version_compare($version, '3.23.23', '>=') && ($table_type == 'MYISAM' || $table_type == 'ARIA'))

		{
return true;

		{
return true;

		}
elseif(version_compare($version, '5.6', '>=') && $table_type == 'INNODB')
{

		}
elseif(version_compare($version, '5.6', '>=') && $table_type == 'INNODB')
{

Zeile 1231Zeile 1243
	 * @param string $name The index name, optional.
*/
function create_fulltext_index($table, $column, $name="")

	 * @param string $name The index name, optional.
*/
function create_fulltext_index($table, $column, $name="")

	{
$this->write_query("

	{
$this->write_query("

			ALTER TABLE {$this->table_prefix}$table
ADD FULLTEXT $name ($column)
");

			ALTER TABLE {$this->table_prefix}$table
ADD FULLTEXT $name ($column)
");

Zeile 1273Zeile 1285
		if($hard == false)
{
$this->write_query('DROP TABLE IF EXISTS '.$table_prefix.$table);

		if($hard == false)
{
$this->write_query('DROP TABLE IF EXISTS '.$table_prefix.$table);

		}
else

		}
else

		{
$this->write_query('DROP TABLE '.$table_prefix.$table);
}

		{
$this->write_query('DROP TABLE '.$table_prefix.$table);
}

Zeile 1293Zeile 1305
		if($table_prefix == false)
{
$table_prefix = "";

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

		}
else

		}
else

		{
$table_prefix = $this->table_prefix;
}

		{
$table_prefix = $this->table_prefix;
}

Zeile 1356Zeile 1368
		$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 1379Zeile 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)
{

		$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 1395Zeile 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)

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

	}

/**

	}

/**