2009-05-08 08:31:56 +00:00
|
|
|
<?php
|
2009-06-21 23:20:32 +00:00
|
|
|
// PDO can be used in several database drivers
|
2009-05-08 08:31:56 +00:00
|
|
|
if (extension_loaded('pdo')) {
|
|
|
|
class Min_PDO extends PDO {
|
|
|
|
var $_result, $server_info, $affected_rows, $error;
|
|
|
|
|
|
|
|
function __construct() {
|
|
|
|
}
|
|
|
|
|
2009-05-29 20:30:16 +00:00
|
|
|
function dsn($dsn, $username, $password) {
|
2009-05-08 08:31:56 +00:00
|
|
|
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) {
|
2009-06-21 23:20:32 +00:00
|
|
|
// database selection is separated from the connection so dbname in DSN can't be used
|
2009-05-08 08:31:56 +00:00
|
|
|
return $this->query("USE " . idf_escape($database));
|
|
|
|
}
|
|
|
|
|
2009-10-13 10:13:16 +00:00
|
|
|
function query($query, $unbuffered = false) {
|
2010-02-18 16:39:00 +00:00
|
|
|
$return = parent::query($query);
|
|
|
|
if (!$return) {
|
2009-05-08 08:31:56 +00:00
|
|
|
$errorInfo = $this->errorInfo();
|
|
|
|
$this->error = $errorInfo[2];
|
|
|
|
return false;
|
|
|
|
}
|
2010-02-18 16:39:00 +00:00
|
|
|
if ($return->columnCount()) {
|
|
|
|
$this->affected_rows = $return->rowCount();
|
|
|
|
} else {
|
|
|
|
$return->num_rows = $return->rowCount(); // is not guaranteed to work with all drivers
|
2009-05-08 08:31:56 +00:00
|
|
|
}
|
2010-02-18 16:39:00 +00:00
|
|
|
return $return;
|
2009-05-08 08:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function multi_query($query) {
|
2010-02-18 16:39:00 +00:00
|
|
|
return $this->_result = $this->query($query);
|
2009-05-08 08:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function store_result() {
|
2010-02-18 16:39:00 +00:00
|
|
|
$return = &$this->_result;
|
|
|
|
if ($return->columnCount()) {
|
|
|
|
$this->affected_rows = $return->rowCount();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
$return->num_rows = $return->rowCount();
|
|
|
|
return $return;
|
2009-05-08 08:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function next_result() {
|
|
|
|
return $this->_result->nextRowset();
|
|
|
|
}
|
|
|
|
|
|
|
|
function result($result, $field = 0) {
|
|
|
|
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;
|
|
|
|
$row->charsetnr = (in_array("blob", $row->flags) ? 63 : 0);
|
|
|
|
return $row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|