Permalink
Browse files

Separate PDO

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@605 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent 8598a97 commit 5ef932261612ab2d2892e13dba3c8fb84c3ad4d3 jakubvrana committed May 8, 2009
Showing with 89 additions and 78 deletions.
  1. +1 −1 _compile.php
  2. +1 −0 index.php
  3. +3 −77 mysql.inc.php
  4. +84 −0 pdo.inc.php
View
@@ -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();
View
@@ -49,6 +49,7 @@ function save_coverage() {
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";
View
@@ -171,88 +171,14 @@ function free() {
$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;
View
@@ -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
+ }
+ }
+}

0 comments on commit 5ef9322

Please sign in to comment.