adminerevo/adminer/include/pdo.inc.php

95 lines
2.4 KiB
PHP
Raw Normal View History

<?php
// PDO can be used in several database drivers
if (extension_loaded('pdo')) {
2010-05-27 11:32:58 +00:00
/*abstract*/ class Min_PDO extends PDO {
2013-01-10 06:19:38 +00:00
var $_result, $server_info, $affected_rows, $errno, $error;
function __construct() {
2011-09-18 07:07:12 +00:00
global $adminer;
$pos = array_search("", $adminer->operators);
if ($pos !== false) {
unset($adminer->operators[$pos]);
}
}
function dsn($dsn, $username, $password, $exception_handler = 'auth_error') {
set_exception_handler($exception_handler); // try/catch is not compatible with PHP 4
parent::__construct($dsn, $username, $password);
restore_exception_handler();
$this->setAttribute(13, array('Min_PDOStatement')); // 13 - PDO::ATTR_STATEMENT_CLASS
$this->server_info = $this->getAttribute(4); // 4 - PDO::ATTR_SERVER_VERSION
}
/*abstract function select_db($database);*/
function query($query, $unbuffered = false) {
$result = parent::query($query);
2012-07-15 16:21:22 +00:00
$this->error = "";
if (!$result) {
2013-01-10 06:19:38 +00:00
list(, $this->errno, $this->error) = $this->errorInfo();
return false;
}
$this->store_result($result);
return $result;
}
function multi_query($query) {
return $this->_result = $this->query($query);
}
function store_result($result = null) {
if (!$result) {
$result = $this->_result;
2013-01-10 20:57:00 +00:00
if (!$result) {
return false;
}
}
if ($result->columnCount()) {
$result->num_rows = $result->rowCount(); // is not guaranteed to work with all drivers
return $result;
}
$this->affected_rows = $result->rowCount();
return true;
}
function next_result() {
2013-01-10 20:57:00 +00:00
if (!$this->_result) {
return false;
}
$this->_result->_offset = 0;
2012-05-14 07:54:28 +00:00
return @$this->_result->nextRowset(); // @ - PDO_PgSQL doesn't support it
}
function result($query, $field = 0) {
$result = $this->query($query);
if (!$result) {
return false;
}
$row = $result->fetch();
return $row[$field];
}
}
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;
2012-05-14 07:54:28 +00:00
$row->charsetnr = (in_array("blob", (array) $row->flags) ? 63 : 0);
return $row;
}
}
}
$drivers = array();