adminerevo/adminer/include/pdo.inc.php

103 lines
2.5 KiB
PHP
Raw Permalink Normal View History

<?php
// PDO can be used in several database drivers
if (extension_loaded('pdo')) {
2020-10-20 19:04:33 +00:00
/*abstract*/ class Min_PDO {
var $_result, $server_info, $affected_rows, $errno, $error, $pdo;
2023-05-21 13:03:36 +00:00
function __construct() {
2011-09-18 07:07:12 +00:00
global $adminer;
2013-04-26 19:04:28 +00:00
$pos = array_search("SQL", $adminer->operators);
2011-09-18 07:07:12 +00:00
if ($pos !== false) {
unset($adminer->operators[$pos]);
}
}
2023-05-21 13:03:36 +00:00
2018-02-07 11:13:58 +00:00
function dsn($dsn, $username, $password, $options = array()) {
$options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT;
$options[PDO::ATTR_STATEMENT_CLASS] = array('Min_PDOStatement');
2013-08-08 23:44:39 +00:00
try {
2020-10-20 19:04:33 +00:00
$this->pdo = new PDO($dsn, $username, $password, $options);
2013-08-08 23:44:39 +00:00
} catch (Exception $ex) {
2017-03-01 10:23:20 +00:00
auth_error(h($ex->getMessage()));
2013-08-08 23:44:39 +00:00
}
$this->server_info = @$this->pdo->getAttribute(PDO::ATTR_SERVER_VERSION);
}
2023-05-21 13:03:36 +00:00
/*abstract function select_db($database);*/
2023-05-21 13:03:36 +00:00
2020-12-06 12:00:03 +00:00
function quote($string) {
return $this->pdo->quote($string);
}
2023-05-21 13:03:36 +00:00
function query($query, $unbuffered = false) {
2020-10-20 19:04:33 +00:00
$result = $this->pdo->query($query);
2012-07-15 16:21:22 +00:00
$this->error = "";
if (!$result) {
2020-10-20 19:04:33 +00:00
list(, $this->errno, $this->error) = $this->pdo->errorInfo();
2018-06-26 06:53:12 +00:00
if (!$this->error) {
$this->error = lang('Unknown error.');
}
return false;
}
$this->store_result($result);
return $result;
}
2023-05-21 13:03:36 +00:00
function multi_query($query) {
return $this->_result = $this->query($query);
}
2023-05-21 13:03:36 +00:00
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;
}
2023-05-21 13:03:36 +00:00
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
}
2023-05-21 13:03:36 +00:00
function result($query, $field = 0) {
$result = $this->query($query);
if (!$result) {
return false;
}
$row = $result->fetch();
return $row[$field];
}
}
2023-05-21 13:03:36 +00:00
class Min_PDOStatement extends PDOStatement {
var $_offset = 0, $num_rows;
2023-05-21 13:03:36 +00:00
function fetch_assoc() {
return $this->fetch(PDO::FETCH_ASSOC);
}
2023-05-21 13:03:36 +00:00
function fetch_row() {
return $this->fetch(PDO::FETCH_NUM);
}
2023-05-21 13:03:36 +00:00
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;
}
}
}