2007-07-10 06:28:25 +00:00
|
|
|
<?php
|
|
|
|
if (extension_loaded("mysqli")) {
|
|
|
|
class Min_MySQLi extends MySQLi {
|
2008-03-18 12:31:45 +00:00
|
|
|
var $extension = "MySQLi";
|
|
|
|
|
2007-07-10 13:30:42 +00:00
|
|
|
function Min_MySQLi() {
|
2009-04-15 14:31:05 +00:00
|
|
|
parent::init();
|
2007-07-10 13:30:42 +00:00
|
|
|
}
|
|
|
|
|
2007-11-08 12:20:18 +00:00
|
|
|
function connect($server, $username, $password) {
|
|
|
|
list($host, $port) = explode(":", $server, 2);
|
2009-04-15 14:31:05 +00:00
|
|
|
return @parent::real_connect(
|
2007-11-08 12:20:18 +00:00
|
|
|
(strlen($server) ? $host : ini_get("mysqli.default_host")),
|
2007-07-10 13:30:42 +00:00
|
|
|
(strlen("$server$username") ? $username : ini_get("mysqli.default_user")),
|
2007-09-30 10:19:06 +00:00
|
|
|
(strlen("$server$username$password") ? $password : ini_get("mysqli.default_pw")),
|
|
|
|
null,
|
|
|
|
(strlen($port) ? $port : ini_get("mysqli.default_port"))
|
2007-07-10 13:30:42 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2007-07-11 08:24:03 +00:00
|
|
|
function result($result, $field = 0) {
|
2008-09-30 09:40:38 +00:00
|
|
|
if (!$result) {
|
|
|
|
return false;
|
|
|
|
}
|
2009-04-15 14:31:05 +00:00
|
|
|
$row = $result->_result->fetch_array();
|
2007-07-10 06:28:25 +00:00
|
|
|
return $row[$field];
|
|
|
|
}
|
2009-04-15 14:31:05 +00:00
|
|
|
|
|
|
|
// minification compatibility start
|
|
|
|
function select_db($database) {
|
|
|
|
return parent::select_db($database);
|
|
|
|
}
|
|
|
|
|
|
|
|
function query($query) {
|
|
|
|
$result = parent::query($query);
|
|
|
|
return (is_object($result) ? new Min_MySQLiResult($result) : $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
function multi_query($query) {
|
|
|
|
return parent::multi_query($query);
|
|
|
|
}
|
|
|
|
|
|
|
|
function store_result() {
|
|
|
|
$result = parent::store_result();
|
|
|
|
return (is_object($result) ? new Min_MySQLiResult($result) : $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
function next_result() {
|
|
|
|
return parent::next_result();
|
|
|
|
}
|
|
|
|
|
|
|
|
function escape_string($string) {
|
|
|
|
return parent::escape_string($string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Min_MySQLiResult {
|
|
|
|
var $_result, $num_rows;
|
|
|
|
|
|
|
|
function __construct($result) {
|
|
|
|
$this->_result = $result;
|
|
|
|
$this->num_rows = $result->num_rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
function fetch_assoc() {
|
|
|
|
return $this->_result->fetch_assoc();
|
|
|
|
}
|
|
|
|
|
|
|
|
function fetch_row() {
|
|
|
|
return $this->_result->fetch_row();
|
|
|
|
}
|
|
|
|
|
|
|
|
function fetch_field() {
|
|
|
|
return $this->_result->fetch_field();
|
|
|
|
}
|
|
|
|
|
|
|
|
function free() {
|
|
|
|
return $this->_result->free();
|
|
|
|
}
|
|
|
|
// minification compatibility end
|
2007-07-10 06:28:25 +00:00
|
|
|
}
|
2007-07-10 13:30:42 +00:00
|
|
|
|
|
|
|
$mysql = new Min_MySQLi;
|
|
|
|
|
2007-07-10 06:28:25 +00:00
|
|
|
} elseif (extension_loaded("mysql")) {
|
|
|
|
class Min_MySQL {
|
2008-03-18 12:31:45 +00:00
|
|
|
var $extension = "MySQL", $_link, $_result, $server_info, $affected_rows, $error;
|
2007-07-10 13:30:42 +00:00
|
|
|
|
2007-11-08 12:20:18 +00:00
|
|
|
function connect($server, $username, $password) {
|
2007-08-31 08:48:13 +00:00
|
|
|
$this->_link = @mysql_connect(
|
2007-11-08 12:20:18 +00:00
|
|
|
(strlen($server) ? $server : ini_get("mysql.default_host")),
|
2007-07-10 13:30:42 +00:00
|
|
|
(strlen("$server$username") ? $username : ini_get("mysql.default_user")),
|
|
|
|
(strlen("$server$username$password") ? $password : ini_get("mysql.default_password")),
|
|
|
|
131072 // CLIENT_MULTI_RESULTS for CALL
|
|
|
|
);
|
|
|
|
if ($this->_link) {
|
|
|
|
$this->server_info = mysql_get_server_info($this->_link);
|
|
|
|
}
|
|
|
|
return (bool) $this->_link;
|
|
|
|
}
|
|
|
|
|
2007-07-23 11:57:26 +00:00
|
|
|
function select_db($database) {
|
|
|
|
return mysql_select_db($database, $this->_link);
|
|
|
|
}
|
|
|
|
|
2007-07-10 13:30:42 +00:00
|
|
|
function query($query) {
|
|
|
|
$result = mysql_query($query, $this->_link);
|
|
|
|
if (!$result) {
|
|
|
|
$this->error = mysql_error($this->_link);
|
|
|
|
return false;
|
|
|
|
} elseif ($result === true) {
|
|
|
|
$this->affected_rows = mysql_affected_rows($this->_link);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return new Min_MySQLResult($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
function multi_query($query) {
|
|
|
|
return $this->_result = $this->query($query);
|
|
|
|
}
|
|
|
|
|
|
|
|
function store_result() {
|
|
|
|
return $this->_result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function next_result() {
|
|
|
|
return false;
|
|
|
|
}
|
2007-07-23 11:57:26 +00:00
|
|
|
|
2007-07-11 08:24:03 +00:00
|
|
|
function result($result, $field = 0) {
|
2008-09-30 09:40:38 +00:00
|
|
|
if (!$result) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-07-11 08:24:03 +00:00
|
|
|
return mysql_result($result->_result, 0, $field);
|
2007-07-10 13:30:42 +00:00
|
|
|
}
|
|
|
|
|
2007-07-10 14:16:44 +00:00
|
|
|
function escape_string($string) {
|
2007-07-10 13:30:42 +00:00
|
|
|
return mysql_real_escape_string($string, $this->_link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Min_MySQLResult {
|
2007-07-23 11:57:26 +00:00
|
|
|
var $_result, $_offset = 0, $num_rows;
|
2007-07-10 13:30:42 +00:00
|
|
|
|
|
|
|
function Min_MySQLResult($result) {
|
|
|
|
$this->_result = $result;
|
|
|
|
$this->num_rows = mysql_num_rows($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
function fetch_assoc() {
|
|
|
|
return mysql_fetch_assoc($this->_result);
|
|
|
|
}
|
|
|
|
|
|
|
|
function fetch_row() {
|
|
|
|
return mysql_fetch_row($this->_result);
|
|
|
|
}
|
|
|
|
|
|
|
|
function fetch_field() {
|
|
|
|
$row = mysql_fetch_field($this->_result, $this->_offset++);
|
2007-07-10 06:28:25 +00:00
|
|
|
$row->orgtable = $row->table;
|
|
|
|
$row->orgname = $row->name;
|
|
|
|
$row->charsetnr = ($row->blob ? 63 : 0);
|
|
|
|
return $row;
|
|
|
|
}
|
2007-07-10 13:30:42 +00:00
|
|
|
|
|
|
|
function free() {
|
|
|
|
return mysql_free_result($this->_result);
|
|
|
|
}
|
2007-07-10 06:28:25 +00:00
|
|
|
}
|
2007-07-10 13:30:42 +00:00
|
|
|
|
2007-07-10 06:28:25 +00:00
|
|
|
$mysql = new Min_MySQL;
|
2007-07-10 13:30:42 +00:00
|
|
|
|
2007-07-23 11:57:26 +00:00
|
|
|
} elseif (extension_loaded("pdo_mysql")) {
|
|
|
|
class Min_PDO_MySQL extends PDO {
|
2008-03-18 12:31:45 +00:00
|
|
|
var $extension = "PDO_MySQL", $_result, $server_info, $affected_rows, $error;
|
2007-07-23 11:57:26 +00:00
|
|
|
|
|
|
|
function __construct() {
|
|
|
|
}
|
|
|
|
|
2007-11-08 12:20:18 +00:00
|
|
|
function connect($server, $username, $password) {
|
2007-07-23 11:57:26 +00:00
|
|
|
set_exception_handler('auth_error'); // try/catch is not compatible with PHP 4
|
2007-11-08 12:20:18 +00:00
|
|
|
parent::__construct("mysql:host=" . str_replace(":", ";port=", $server), $username, $password);
|
2007-07-23 11:57:26 +00:00
|
|
|
restore_exception_handler();
|
2009-04-15 14:31:05 +00:00
|
|
|
parent::setAttribute(13, array('Min_PDOStatement')); // PDO::ATTR_STATEMENT_CLASS
|
2007-07-23 11:57:26 +00:00
|
|
|
$this->server_info = $this->result($this->query("SELECT VERSION()"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function select_db($database) {
|
2007-07-24 05:48:13 +00:00
|
|
|
return $this->query("USE " . idf_escape($database));
|
2007-07-23 11:57:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function query($query) {
|
2009-04-15 14:31:05 +00:00
|
|
|
$_result = parent::query($query);
|
|
|
|
if (!$_result) {
|
|
|
|
$errorInfo = parent::errorInfo();
|
2007-07-23 11:57:26 +00:00
|
|
|
$this->error = $errorInfo[2];
|
|
|
|
return false;
|
|
|
|
}
|
2009-04-15 14:31:05 +00:00
|
|
|
$this->_result = $_result;
|
|
|
|
if (!$_result->columnCount()) {
|
|
|
|
$this->affected_rows = $_result->rowCount();
|
2007-07-23 11:57:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-04-15 14:31:05 +00:00
|
|
|
$_result->num_rows = $_result->rowCount();
|
|
|
|
return $_result;
|
2007-07-23 11:57:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function multi_query($query) {
|
|
|
|
return $this->query($query);
|
|
|
|
}
|
|
|
|
|
|
|
|
function store_result() {
|
|
|
|
return ($this->_result->columnCount() ? $this->_result : true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function next_result() {
|
|
|
|
return $this->_result->nextRowset();
|
|
|
|
}
|
|
|
|
|
2009-04-15 14:31:05 +00:00
|
|
|
function result($_result, $field = 0) {
|
|
|
|
if (!$_result) {
|
2008-09-30 09:40:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-04-15 14:31:05 +00:00
|
|
|
$row = $_result->fetch();
|
2007-07-23 11:57:26 +00:00
|
|
|
return $row[$field];
|
|
|
|
}
|
|
|
|
|
|
|
|
function escape_string($string) {
|
2009-04-15 14:31:05 +00:00
|
|
|
return substr(parent::quote($string), 1, -1);
|
2007-07-23 11:57:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Min_PDOStatement extends PDOStatement {
|
|
|
|
var $_offset = 0, $num_rows;
|
|
|
|
|
|
|
|
function fetch_assoc() {
|
2009-04-15 14:31:05 +00:00
|
|
|
return parent::fetch(2); // PDO::FETCH_ASSOC
|
2007-07-23 11:57:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function fetch_row() {
|
2009-04-15 14:31:05 +00:00
|
|
|
return parent::fetch(3); // PDO::FETCH_NUM
|
2007-07-23 11:57:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function fetch_field() {
|
2009-04-15 14:31:05 +00:00
|
|
|
$row = (object) parent::getColumnMeta($this->_offset++);
|
2007-08-10 12:22:37 +00:00
|
|
|
$row->orgtable = $row->table;
|
|
|
|
$row->orgname = $row->name;
|
|
|
|
$row->charsetnr = (in_array("blob", $row->flags) ? 63 : 0);
|
2007-07-23 11:57:26 +00:00
|
|
|
return $row;
|
|
|
|
}
|
|
|
|
|
|
|
|
function free() {
|
|
|
|
// $this->__destruct() is not callable
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$mysql = new Min_PDO_MySQL;
|
|
|
|
|
2007-07-10 06:28:25 +00:00
|
|
|
} else {
|
2008-05-23 13:31:55 +00:00
|
|
|
page_header(lang('No MySQL extension'), lang('None of supported PHP extensions (%s) are available.', 'MySQLi, MySQL, PDO_MySQL'), null);
|
2007-07-10 13:30:42 +00:00
|
|
|
page_footer("auth");
|
|
|
|
exit;
|
2007-07-10 06:28:25 +00:00
|
|
|
}
|