Line 27 | Line 27 |
---|
class dbal_mysqli extends dbal { var $multi_insert = true;
|
class dbal_mysqli extends dbal { var $multi_insert = true;
|
| var $connect_error = '';
|
/** * Connect to server */ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false , $new_link = false) {
|
/** * Connect to server */ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false , $new_link = false) {
|
$this->persistency = $persistency;
| if (!function_exists('mysqli_connect')) { $this->connect_error = 'mysqli_connect function does not exist, is mysqli extension installed?'; return $this->sql_error(''); }
// Mysqli extension supports persistent connection since PHP 5.3.0 $this->persistency = (version_compare(PHP_VERSION, '5.3.0', '>=')) ? $persistency : false;
|
$this->user = $sqluser;
|
$this->user = $sqluser;
|
$this->server = $sqlserver;
| // If persistent connection, set dbhost to localhost when empty and prepend it with 'p:' prefix $this->server = ($this->persistency) ? 'p:' . (($sqlserver) ? $sqlserver : 'localhost') : $sqlserver;
|
$this->dbname = $database; $port = (!$port) ? NULL : $port;
|
$this->dbname = $database; $port = (!$port) ? NULL : $port;
|
// Persistant connections not supported by the mysqli extension? $this->db_connect_id = @mysqli_connect($this->server, $this->user, $sqlpassword, $this->dbname, $port);
| // If port is set and it is not numeric, most likely mysqli socket is set. // Try to map it to the $socket parameter. $socket = NULL; if ($port) { if (is_numeric($port)) { $port = (int) $port; } else { $socket = $port; $port = NULL; } }
$this->db_connect_id = @mysqli_connect($this->server, $this->user, $sqlpassword, $this->dbname, $port, $socket);
|
if ($this->db_connect_id && $this->dbname != '') {
| if ($this->db_connect_id && $this->dbname != '') {
|
Line 80 | Line 106 |
---|
/** * Version information about used database
|
/** * Version information about used database
|
* @param bool $raw if true, only return the fetched sql_server_version
| * @param bool $use_cache If true, it is safe to retrieve the value from the cache
|
* @return string sql server version */
|
* @return string sql server version */
|
function sql_server_info($raw = false)
| function sql_server_info($raw = false, $use_cache = true)
|
{ global $cache;
|
{ global $cache;
|
if (empty($cache) || ($this->sql_server_version = $cache->get('mysqli_version')) === false)
| if (!$use_cache || empty($cache) || ($this->sql_server_version = $cache->get('mysqli_version')) === false)
|
{ $result = @mysqli_query($this->db_connect_id, 'SELECT VERSION() AS version'); $row = @mysqli_fetch_assoc($result);
| { $result = @mysqli_query($this->db_connect_id, 'SELECT VERSION() AS version'); $row = @mysqli_fetch_assoc($result);
|
Line 95 | Line 121 |
---|
$this->sql_server_version = $row['version'];
|
$this->sql_server_version = $row['version'];
|
if (!empty($cache))
| if (!empty($cache) && $use_cache)
|
{ $cache->put('mysqli_version', $this->sql_server_version); }
| { $cache->put('mysqli_version', $this->sql_server_version); }
|
Line 230 | Line 256 |
---|
return $cache->sql_fetchrow($query_id); }
|
return $cache->sql_fetchrow($query_id); }
|
return ($query_id !== false) ? @mysqli_fetch_assoc($query_id) : false;
| if ($query_id !== false) { $result = @mysqli_fetch_assoc($query_id); return $result !== null ? $result : false; }
return false;
|
}
/**
| }
/**
|
Line 288 | Line 320 |
---|
function sql_escape($msg) { return @mysqli_real_escape_string($this->db_connect_id, $msg);
|
function sql_escape($msg) { return @mysqli_real_escape_string($this->db_connect_id, $msg);
|
| }
/** * Gets the estimated number of rows in a specified table. * * @param string $table_name Table name * * @return string Number of rows in $table_name. * Prefixed with ~ if estimated (otherwise exact). * * @access public */ function get_estimated_row_count($table_name) { $table_status = $this->get_table_status($table_name);
if (isset($table_status['Engine'])) { if ($table_status['Engine'] === 'MyISAM') { return $table_status['Rows']; } else if ($table_status['Engine'] === 'InnoDB' && $table_status['Rows'] > 100000) { return '~' . $table_status['Rows']; } }
return parent::get_row_count($table_name); }
/** * Gets the exact number of rows in a specified table. * * @param string $table_name Table name * * @return string Exact number of rows in $table_name. * * @access public */ function get_row_count($table_name) { $table_status = $this->get_table_status($table_name);
if (isset($table_status['Engine']) && $table_status['Engine'] === 'MyISAM') { return $table_status['Rows']; }
return parent::get_row_count($table_name); }
/** * Gets some information about the specified table. * * @param string $table_name Table name * * @return array * * @access protected */ function get_table_status($table_name) { $sql = "SHOW TABLE STATUS LIKE '" . $this->sql_escape($table_name) . "'"; $result = $this->sql_query($sql); $table_status = $this->sql_fetchrow($result); $this->sql_freeresult($result);
return $table_status;
|
}
/**
| }
/**
|
Line 321 | Line 423 |
---|
*/ function _sql_error() {
|
*/ function _sql_error() {
|
if (!$this->db_connect_id)
| if ($this->db_connect_id)
|
{
|
{
|
return array(
| $error = array( 'message' => @mysqli_error($this->db_connect_id), 'code' => @mysqli_errno($this->db_connect_id) ); } else if (function_exists('mysqli_connect_error')) { $error = array(
|
'message' => @mysqli_connect_error(),
|
'message' => @mysqli_connect_error(),
|
'code' => @mysqli_connect_errno()
| 'code' => @mysqli_connect_errno(),
|
); }
|
); }
|
return array( 'message' => @mysqli_error($this->db_connect_id), 'code' => @mysqli_errno($this->db_connect_id)
| else { $error = array( 'message' => $this->connect_error, 'code' => '',
|
);
|
);
|
| }
return $error;
|
}
/**
| }
/**
|