mirror of
https://github.com/vrana/adminer.git
synced 2026-02-26 16:41:29 +01:00
Separate PDO
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@605 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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;
|
||||
|
||||
84
pdo.inc.php
Normal file
84
pdo.inc.php
Normal file
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user