From: jakubvrana Date: Fri, 8 May 2009 08:31:56 +0000 (+0000) Subject: Separate PDO X-Git-Tag: v3.0.0~917 X-Git-Url: https://git.joonet.de/?a=commitdiff_plain;h=5ef932261612ab2d2892e13dba3c8fb84c3ad4d3;p=adminer.git Separate PDO git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@605 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- diff --git a/_compile.php b/_compile.php index c72ff115..08ac0396 100644 --- a/_compile.php +++ b/_compile.php @@ -74,7 +74,7 @@ function short_identifier($number, $chars) { return $return; } -// Based on Dgx's PHP shrinker +// based on Dgx's PHP shrinker function php_shrink($input) { $special_variables = array_flip(array('$this', '$GLOBALS', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_SERVER')); static $short_variables = array(); diff --git a/index.php b/index.php index 8d2f3920..2ac02967 100644 --- a/index.php +++ b/index.php @@ -49,6 +49,7 @@ $SELF = preg_replace('~^[^?]*/([^?]*).*~', '\\1?', $_SERVER["REQUEST_URI"]) . (s include "./functions.inc.php"; include "./lang.inc.php"; include "./lang/$LANG.inc.php"; +include "./pdo.inc.php"; include "./mysql.inc.php"; include "./design.inc.php"; include "./auth.inc.php"; diff --git a/mysql.inc.php b/mysql.inc.php index 4a22c154..257c9d1b 100644 --- a/mysql.inc.php +++ b/mysql.inc.php @@ -171,88 +171,14 @@ if (extension_loaded("mysqli")) { $dbh = new Min_MySQL; } elseif (extension_loaded("pdo_mysql")) { - class Min_PDO_MySQL extends PDO { - var $extension = "PDO_MySQL", $_result, $server_info, $affected_rows, $error; - - function __construct() { - } + class Min_PDO_MySQL extends Min_PDO { + var $extension = "PDO_MySQL"; function connect($server, $username, $password) { - set_exception_handler('auth_error'); // try/catch is not compatible with PHP 4 - parent::__construct("mysql:host=" . str_replace(":", ";port=", $server), $username, $password); - restore_exception_handler(); - $this->setAttribute(13, array('Min_PDOStatement')); // PDO::ATTR_STATEMENT_CLASS + $this->dsn("mysql:host=" . str_replace(":", ";port=", $server), $username, $password); $this->server_info = $this->result($this->query("SELECT VERSION()")); return true; } - - function select_db($database) { - return $this->query("USE " . idf_escape($database)); - } - - function query($query) { - $result = parent::query($query); - if (!$result) { - $errorInfo = $this->errorInfo(); - $this->error = $errorInfo[2]; - return false; - } - $this->_result = $result; - if (!$result->columnCount()) { - $this->affected_rows = $result->rowCount(); - return true; - } - $result->num_rows = $result->rowCount(); - return $result; - } - - 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(); - } - - function result($result, $field = 0) { - if (!$result) { - return false; - } - $row = $result->fetch(); - return $row[$field]; - } - - function escape_string($string) { - return substr($this->quote($string), 1, -1); - } - } - - class Min_PDOStatement extends PDOStatement { - var $_offset = 0, $num_rows; - - function fetch_assoc() { - return $this->fetch(2); // PDO::FETCH_ASSOC - } - - function fetch_row() { - return $this->fetch(3); // PDO::FETCH_NUM - } - - function fetch_field() { - $row = (object) $this->getColumnMeta($this->_offset++); - $row->orgtable = $row->table; - $row->orgname = $row->name; - $row->charsetnr = (in_array("blob", $row->flags) ? 63 : 0); - return $row; - } - - function free() { - // $this->__destruct() is not callable - } } $dbh = new Min_PDO_MySQL; diff --git a/pdo.inc.php b/pdo.inc.php new file mode 100644 index 00000000..5e411b7b --- /dev/null +++ b/pdo.inc.php @@ -0,0 +1,84 @@ +setAttribute(13, array('Min_PDOStatement')); // PDO::ATTR_STATEMENT_CLASS + } + + function select_db($database) { + return $this->query("USE " . idf_escape($database)); + } + + function query($query) { + $result = parent::query($query); + if (!$result) { + $errorInfo = $this->errorInfo(); + $this->error = $errorInfo[2]; + return false; + } + $this->_result = $result; + if (!$result->columnCount()) { + $this->affected_rows = $result->rowCount(); + return true; + } + $result->num_rows = $result->rowCount(); + return $result; + } + + 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(); + } + + function result($result, $field = 0) { + if (!$result) { + return false; + } + $row = $result->fetch(); + return $row[$field]; + } + + function escape_string($string) { + return substr($this->quote($string), 1, -1); + } + } + + class Min_PDOStatement extends PDOStatement { + var $_offset = 0, $num_rows; + + function fetch_assoc() { + return $this->fetch(2); // PDO::FETCH_ASSOC + } + + function fetch_row() { + return $this->fetch(3); // PDO::FETCH_NUM + } + + function fetch_field() { + $row = (object) $this->getColumnMeta($this->_offset++); + $row->orgtable = $row->table; + $row->orgname = $row->name; + $row->charsetnr = (in_array("blob", $row->flags) ? 63 : 0); + return $row; + } + + function free() { + // $this->__destruct() is not callable + } + } +}