Zeile 72 | Zeile 72 |
---|
* @var resource */ public $current_link;
|
* @var resource */ public $current_link;
|
| /** * The database name. * * @var string */ public $database;
|
/** * Explanation of a query.
| /** * Explanation of a query.
|
Zeile 103 | Zeile 110 |
---|
/** * The extension used to run the SQL database
|
/** * The extension used to run the SQL database
|
*
| *
|
* @var string */ public $engine = "mysql";
| * @var string */ public $engine = "mysql";
|
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 163 | Zeile 170 |
---|
$connections['read'][] = $settings; } }
|
$connections['read'][] = $settings; } }
|
}
| }
|
// Specified both read & write servers else {
| // Specified both read & write servers else {
|
Zeile 193 | Zeile 200 |
---|
// Loop-de-loop foreach($connections[$type] as $single_connection)
|
// Loop-de-loop foreach($connections[$type] as $single_connection)
|
{
| {
|
$connect_function = "mysql_connect"; if(isset($single_connection['pconnect'])) {
| $connect_function = "mysql_connect"; if(isset($single_connection['pconnect'])) {
|
Zeile 226 | Zeile 233 |
---|
if(!array_key_exists('write', $connections)) { $this->write_link = &$this->read_link;
|
if(!array_key_exists('write', $connections)) { $this->write_link = &$this->read_link;
|
}
| }
|
// Have no read connection? if(!$this->read_link)
| // Have no read connection? if(!$this->read_link)
|
Zeile 250 | Zeile 257 |
---|
$this->current_link = &$this->read_link; return $this->read_link; }
|
$this->current_link = &$this->read_link; return $this->read_link; }
|
|
|
/** * Selects the database to use. *
| /** * Selects the database to use. *
|
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 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)."%' "); } 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' AND `Tables_in_$database` LIKE '".$this->escape_string($prefix)."%'"); } else { $query = $this->query("SHOW TABLES FROM `$database` LIKE '".$this->escape_string($prefix)."%'"); } } else { 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(); while(list($table) = mysql_fetch_array($query)) { $tables[] = $table;
|
}
$tables = array(); while(list($table) = mysql_fetch_array($query)) { $tables[] = $table;
|
}
| }
|
return $tables; }
| return $tables; }
|
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' "); $exists = $this->num_rows($query); if($exists > 0) { return true; } else { return false; }
| 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) { return true; } else { return false; }
|
}
/**
| }
/**
|
Zeile 711 | Zeile 731 |
---|
/** * 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 719 | Zeile 739 |
---|
{ global $shutdown_queries; if($name)
|
{ global $shutdown_queries; if($name)
|
{
| {
|
$shutdown_queries[$name] = $query;
|
$shutdown_queries[$name] = $query;
|
}
| }
|
else { $shutdown_queries[] = $query;
|
else { $shutdown_queries[] = $query;
|
} }
| } }
|
/** * Performs a simple select query. *
| /** * Performs a simple select query. *
|
Zeile 755 | Zeile 775 |
---|
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 800 | Zeile 820 |
---|
else { $array[$field] = $this->quote_val($value);
|
else { $array[$field] = $this->quote_val($value);
|
}
| }
|
}
|
}
|
|
|
$fields = "`".implode("`,`", array_keys($array))."`"; $values = implode(",", $array); $this->write_query("
| $fields = "`".implode("`,`", array_keys($array))."`"; $values = implode(",", $array); $this->write_query("
|
Zeile 811 | Zeile 831 |
---|
VALUES (".$values.") "); return $this->insert_id();
|
VALUES (".$values.") "); return $this->insert_id();
|
}
/**
| }
/**
|
* Build one query for multiple inserts from a multidimensional array. * * @param string $table The table name to perform the query on.
| * Build one query for multiple inserts from a multidimensional array. * * @param string $table The table name to perform the query on.
|
Zeile 827 | Zeile 847 |
---|
if(!is_array($array)) { return;
|
if(!is_array($array)) { return;
|
}
| }
|
// Field names $fields = array_keys($array[0]);
| // Field names $fields = array_keys($array[0]);
|
Zeile 880 | Zeile 900 |
---|
if(!is_array($array)) { return false;
|
if(!is_array($array)) { return false;
|
}
| }
|
$comma = ""; $query = ""; $quote = "'";
| $comma = ""; $query = ""; $quote = "'";
|
Zeile 909 | Zeile 929 |
---|
$query .= $comma."`".$field."`={$quoted_val}"; } $comma = ', ';
|
$query .= $comma."`".$field."`={$quoted_val}"; } $comma = ', ';
|
}
if(!empty($where)) { $query .= " WHERE $where"; }
if(!empty($limit)) { $query .= " LIMIT $limit"; }
| }
if(!empty($where)) { $query .= " WHERE $where"; }
if(!empty($limit)) { $query .= " LIMIT $limit"; }
|
return $this->write_query(" UPDATE {$this->table_prefix}$table
| return $this->write_query(" UPDATE {$this->table_prefix}$table
|
Zeile 934 | Zeile 954 |
---|
* @return int|string */ private function quote_val($value, $quote="'")
|
* @return int|string */ private function quote_val($value, $quote="'")
|
{
| {
|
if(is_int($value))
|
if(is_int($value))
|
{
| {
|
$quoted = $value;
|
$quoted = $value;
|
}
| }
|
else { $quoted = $quote . $value . $quote;
| else { $quoted = $quote . $value . $quote;
|
Zeile 949 | Zeile 969 |
---|
/** * Build a delete query.
|
/** * Build a delete query.
|
*
| *
|
* @param string $table The table name to perform the query on. * @param string $where An optional where clause for the query. * @param string $limit An optional limit clause for the query.
| * @param string $table The table name to perform the query on. * @param string $where An optional where clause for the query. * @param string $limit An optional limit clause for the query.
|
Zeile 964 | Zeile 984 |
---|
}
if(!empty($limit))
|
}
if(!empty($limit))
|
{
| {
|
$query .= " LIMIT $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 977 | Zeile 997 |
---|
/** * 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 1024 | Zeile 1044 |
---|
{ return $this->escape_string(str_replace(array('%', '_') , array('\\%' , '\\_') , $string)); }
|
{ return $this->escape_string(str_replace(array('%', '_') , array('\\%' , '\\_') , $string)); }
|
|
|
/** * Gets the current version of MySQL. *
| /** * Gets the current version of MySQL. *
|
Zeile 1033 | Zeile 1053 |
---|
function get_version() { if($this->version)
|
function get_version() { if($this->version)
|
{
| {
|
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) {
| if($version) {
|
Zeile 1291 | Zeile 1307 |
---|
* * @param string $table The table * @param array $replacements The replacements
|
* * @param string $table The table * @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 1457 | Zeile 1475 |
---|
'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 1523 |
---|
'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',
|