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";
/** * 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 114 | Zeile 119 |
---|
* @var string */ public $engine = "mysql";
|
* @var string */ public $engine = "mysql";
|
|
|
/** * 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 135 | Zeile 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 *
|
Zeile 175 | Zeile 180 |
---|
else { $connections = $config;
|
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 191 | Zeile 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 239 | Zeile 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 485 | Zeile 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 503 | Zeile 515 |
---|
function data_seek($query, $row) { return mysql_data_seek($query, $row);
|
function data_seek($query, $row) { return mysql_data_seek($query, $row);
|
}
| }
|
/** * Return the number of rows resulting from a query. *
| /** * Return the number of rows resulting from a query. *
|
Zeile 514 | Zeile 526 |
---|
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 the last id number of inserted data.
|
Zeile 524 | Zeile 536 |
---|
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 545 | Zeile 557 |
---|
* @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) { return @mysql_errno($this->current_link);
| if($this->current_link) { return @mysql_errno($this->current_link);
|
Zeile 566 | Zeile 578 |
---|
if($this->current_link) { return @mysql_error($this->current_link);
|
if($this->current_link) { return @mysql_error($this->current_link);
|
} else {
| } else {
|
return @mysql_error(); } }
| return @mysql_error(); } }
|
Zeile 603 | Zeile 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.
|
/** * Returns the number of affected rows in a query.
|
*
| *
|
* @return int The number of affected rows.
|
* @return int The number of affected rows.
|
*/
| */
|
function affected_rows() { return mysql_affected_rows($this->current_link);
| function affected_rows() { return mysql_affected_rows($this->current_link);
|
Zeile 630 | Zeile 642 |
---|
* @return int The number of fields. */ function num_fields($query)
|
* @return int The number of fields. */ function num_fields($query)
|
{
| {
|
return mysql_num_fields($query); }
| return mysql_num_fields($query); }
|
Zeile 649 | Zeile 661 |
---|
{ $query = $this->query("SHOW FULL TABLES FROM `$database` WHERE table_type = 'BASE TABLE' AND `Tables_in_$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 { $query = $this->query("SHOW TABLES FROM `$database` LIKE '".$this->escape_string($prefix)."%'"); } }
|
else
|
else
|
{
| {
|
if(version_compare($this->get_version(), '5.0.2', '>=')) { $query = $this->query("SHOW FULL TABLES FROM `$database` WHERE 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'");
|
Zeile 670 | Zeile 682 |
---|
while(list($table) = mysql_fetch_array($query)) { $tables[] = $table;
|
while(list($table) = mysql_fetch_array($query)) { $tables[] = $table;
|
}
| }
|
return $tables; }
| return $tables; }
|
Zeile 691 | Zeile 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)
|
Zeile 731 | Zeile 743 |
---|
/** * Add a shutdown query.
|
/** * Add a shutdown query.
|
*
| *
|
* @param resource $query The query data. * @param string $name An optional name for the query. */
| * @param resource $query The query data. * @param string $name An optional name for the query. */
|
Zeile 792 | Zeile 804 |
---|
/** * Build an insert query from an array.
|
/** * Build an insert query from an array.
|
*
| *
|
* @param string $table The table name to perform the query on. * @param array $array An array of fields and their values. * @return int The insert ID if available
| * @param string $table The table name to perform the query on. * @param array $array An array of fields and their values. * @return int The insert ID if available
|
Zeile 831 | Zeile 843 |
---|
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 894 | Zeile 906 |
---|
* @return resource The query data. */ function update_query($table, $array, $where="", $limit="", $no_quote=false)
|
* @return resource The query data. */ function update_query($table, $array, $where="", $limit="", $no_quote=false)
|
{ global $mybb;
| { global $mybb;
|
if(!is_array($array)) {
| if(!is_array($array)) {
|
Zeile 929 | Zeile 941 |
---|
$query .= $comma."`".$field."`={$quoted_val}"; } $comma = ', ';
|
$query .= $comma."`".$field."`={$quoted_val}"; } $comma = ', ';
|
}
if(!empty($where)) { $query .= " WHERE $where"; }
if(!empty($limit))
| }
if(!empty($where)) { $query .= " WHERE $where"; }
if(!empty($limit))
|
{ $query .= " LIMIT $limit"; }
| { $query .= " LIMIT $limit"; }
|
Zeile 997 | Zeile 1009 |
---|
/** * 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.
| * * @param string $string The string to be escaped.
|
* @return string The escaped string. */ function escape_string($string)
| * @return string The escaped string. */ function escape_string($string)
|
Zeile 1039 | Zeile 1051 |
---|
* * @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 1060 | Zeile 1072 |
---|
$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);
| if($version) { $version = explode(".", $version, 3);
|
Zeile 1353 | Zeile 1365 |
---|
*/ 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
|
*
| *
|
* @param string $table The table * @param string $column The column name * @param string $definition the new column definition * @return resource */ function add_column($table, $column, $definition)
|
* @param string $table The table * @param string $column The column name * @param string $definition the new 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)
| * @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)
|
{
|
{
|
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} {$default}");
|
}
/**
| }
/**
|
Zeile 1389 | Zeile 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)
|
{
|
{
|
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}");
|
}
/**
| }
/**
|