]> git.joonet.de Git - adminer.git/commitdiff
Separate PDO
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Fri, 8 May 2009 08:31:56 +0000 (08:31 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Fri, 8 May 2009 08:31:56 +0000 (08:31 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@605 7c3ca157-0c34-0410-bff1-cbf682f78f5c

_compile.php
index.php
mysql.inc.php
pdo.inc.php [new file with mode: 0644]

index c72ff1152c807a76f08d26332400008490bfab4c..08ac0396a77ea23b060c355b87d2e4a02026ee47 100644 (file)
@@ -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();
index 8d2f3920d6f880654c72460745f4b2de7e1e4bf0..2ac02967a25b79e41d63a717b8b08677e9d54c2c 100644 (file)
--- 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";
index 4a22c1542e63a17dd3cdca1ae4a39c50112b08f6..257c9d1b79942fce36b0a7a61fda7e9c97fbb968 100644 (file)
@@ -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 (file)
index 0000000..5e411b7
--- /dev/null
@@ -0,0 +1,84 @@
+<?php
+if (extension_loaded('pdo')) {
+       class Min_PDO extends PDO {
+               var $_result, $server_info, $affected_rows, $error;
+               
+               function __construct() {
+               }
+               
+               function dsn($dsn, $username = "", $password = "") {
+                       set_exception_handler('auth_error'); // try/catch is not compatible with PHP 4
+                       parent::__construct($dsn, $username, $password);
+                       restore_exception_handler();
+                       $this->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
+               }
+       }
+}