Zeile 74 | Zeile 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 82 | Zeile 89 |
---|
/** * The current version of MySQL.
|
/** * The current version of MySQL.
|
* * @var string
| * * @var string
|
*/ public $version;
| */ public $version;
|
Zeile 93 | Zeile 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 133 | Zeile 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 232 | Zeile 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 259 | Zeile 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 553 | Zeile 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 594 | Zeile 603 |
---|
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; }
|
Zeile 636 | Zeile 645 |
---|
{ 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();
| }
$tables = array();
|
Zeile 668 | Zeile 684 |
---|
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' ");
| 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 883 | Zeile 903 |
---|
}
$comma = "";
|
}
$comma = "";
|
$query = ""; $quote = "'";
| $query = ""; $quote = "'";
|
if($no_quote == true) {
| if($no_quote == true) {
|
Zeile 938 | Zeile 958 |
---|
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 961 | Zeile 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"; }
|
|
|
return $this->write_query(" DELETE FROM {$this->table_prefix}$table
| return $this->write_query(" DELETE FROM {$this->table_prefix}$table
|
Zeile 982 | Zeile 1002 |
---|
* @return string The escaped string. */ function escape_string($string)
|
* @return string The escaped string. */ function escape_string($string)
|
{
| {
|
if($this->db_encoding == 'utf8')
|
if($this->db_encoding == 'utf8')
|
{
| {
|
$string = validate_utf8_string($string, false);
|
$string = validate_utf8_string($string, false);
|
}
| }
|
elseif($this->db_encoding == 'utf8mb4') { $string = validate_utf8_string($string);
|
elseif($this->db_encoding == 'utf8mb4') { $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)
|
{
| {
|
$string = mysql_real_escape_string($string, $this->read_link); } else
| $string = mysql_real_escape_string($string, $this->read_link); } else
|
Zeile 1001 | Zeile 1021 |
---|
$string = addslashes($string); } return $string;
|
$string = addslashes($string); } return $string;
|
}
| }
|
/** * Frees the resources of a MySQLi query. *
| /** * Frees the resources of a MySQLi query. *
|
Zeile 1037 | Zeile 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) { $version = explode(".", $version, 3); $this->version = (int)$version[0].".".(int)$version[1].".".(int)$version[2];
|
if($version) { $version = explode(".", $version, 3); $this->version = (int)$version[0].".".(int)$version[1].".".(int)$version[2];
|
}
| }
|
return $this->version;
|
return $this->version;
|
}
| }
|
/** * Optimizes a specific table. * * @param string $table The name of the table to be optimized.
|
/** * Optimizes a specific 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}");
| function optimize_table($table) { $this->write_query("OPTIMIZE TABLE {$this->table_prefix}{$table}");
|
Zeile 1069 | Zeile 1085 |
---|
* @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)
|
{
| {
|
$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.
|
* * @param string $table The name of the table.
| * * @param string $table The name of the table.
|
* @return string The MySQL command to create the specified table. */ function show_create_table($table)
| * @return string The MySQL command to create the specified table. */ function show_create_table($table)
|
Zeile 1088 | Zeile 1104 |
---|
/** * Show the "show fields from" command for a specific table.
|
/** * Show the "show fields from" command for a specific table.
|
* * @param string $table The name of the table.
| * * @param string $table The name of the table.
|
* @return array Field info for that table */ function show_fields_from($table)
| * @return array Field info for that table */ function show_fields_from($table)
|
Zeile 1109 | Zeile 1125 |
---|
* @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.
|
*/
| */
|
function is_fulltext($table, $index="") { $structure = $this->show_create_table($table); if($index != "")
|
function is_fulltext($table, $index="") { $structure = $this->show_create_table($table); if($index != "")
|
{
| {
|
if(preg_match("#FULLTEXT KEY (`?)$index(`?)#i", $structure))
|
if(preg_match("#FULLTEXT KEY (`?)$index(`?)#i", $structure))
|
{
| {
|
return true;
|
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 1183 | Zeile 1199 |
---|
}
if($index_exists)
|
}
if($index_exists)
|
{ return true; }
return false; }
| { return true; }
return false; }
|
/** * Returns whether or not this database engine supports boolean fulltext matching. *
| /** * Returns whether or not this database engine supports boolean fulltext matching. *
|
Zeile 1209 | Zeile 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 $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 1229 | Zeile 1245 |
---|
* @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 1244 | Zeile 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
| { if($table_prefix == false) { $table_prefix = ""; } else
|
{ $table_prefix = $this->table_prefix; }
| { $table_prefix = $this->table_prefix; }
|
Zeile 1288 | Zeile 1304 |
---|
/** * 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 1309 | Zeile 1327 |
---|
} $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 1328 | Zeile 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 1348 | Zeile 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}");
|
}
/**
| }
/**
|
Zeile 1357 | Zeile 1379 |
---|
* @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}");
|
}
/**
| }
/**
|
Zeile 1371 | Zeile 1422 |
---|
* @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 1457 | Zeile 1538 |
---|
'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 1506 | Zeile 1586 |
---|
'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',
|