Zeile 72 | Zeile 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 93 | Zeile 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 114 | Zeile 119 |
---|
* @var string */ public $engine = "mysql";
|
* @var string */ public $engine = "mysql";
|
/**
| /**
|
* Weather or not this engine can use the search functionality * * @var boolean */ public $can_search = true;
|
* Weather or not this engine can use the search functionality * * @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
|
*/
| */
|
public $db_encoding = "utf8";
/**
| public $db_encoding = "utf8";
/**
|
Zeile 135 | Zeile 140 |
---|
* @var float */ public $query_time = 0;
|
* @var float */ public $query_time = 0;
|
/**
| /**
|
* 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 156 | Zeile 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 170 | Zeile 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'];
// Actually connect to the specified servers
| $this->db_encoding = $config['encoding'];
// Actually connect to the specified servers
|
Zeile 191 | Zeile 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 239 | Zeile 244 |
---|
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 485 | Zeile 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 495 | Zeile 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 507 | Zeile 516 |
---|
/** * 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 518 | Zeile 527 |
---|
/** * 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 528 | Zeile 537 |
---|
/** * Close the connection with the DBMS.
|
/** * Close the connection with the DBMS.
|
*
| *
|
*/ function close() {
| */ function close() {
|
Zeile 536 | Zeile 545 |
---|
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 549 | Zeile 558 |
---|
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 570 | Zeile 579 |
---|
else { return @mysql_error();
|
else { return @mysql_error();
|
} }
| } }
|
/** * Output a database error.
| /** * Output a database error.
|
Zeile 592 | Zeile 601 |
---|
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 603 | Zeile 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; } 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 632 | Zeile 641 |
---|
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 646 | Zeile 655 |
---|
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 673 | Zeile 682 |
---|
}
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 691 | Zeile 700 |
---|
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 736 | Zeile 745 |
---|
* @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 775 | Zeile 784 |
---|
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 900 | Zeile 909 |
---|
if(!is_array($array)) { return false;
|
if(!is_array($array)) { return false;
|
}
| }
|
$comma = ""; $query = ""; $quote = "'";
| $comma = ""; $query = ""; $quote = "'";
|
Zeile 958 | Zeile 967 |
---|
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 984 | Zeile 993 |
---|
}
if(!empty($limit))
|
}
if(!empty($limit))
|
{
| {
|
$query .= " LIMIT $limit"; }
| $query .= " LIMIT $limit"; }
|
Zeile 1025 | Zeile 1034 |
---|
/** * 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 1042 | Zeile 1051 |
---|
*/ 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 1067 | Zeile 1076 |
---|
$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 1075 | Zeile 1084 |
---|
* @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 1087 | Zeile 1096 |
---|
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 1107 | Zeile 1116 |
---|
* * @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 1168 | Zeile 1177 |
---|
$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 1231 | Zeile 1240 |
---|
* @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 1273 | Zeile 1282 |
---|
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 1293 | Zeile 1302 |
---|
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 1356 | Zeile 1365 |
---|
$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 1379 | Zeile 1388 |
---|
* @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 1395 | Zeile 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)
|
{ $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}");
|
}
/**
| }
/**
|