1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-30 01:30:12 +02:00

Cleanup: Definition of custom PDO statement class

This commit is contained in:
Peter Knut
2024-11-10 23:32:31 +01:00
parent 99f4c22c72
commit 638288cc04

View File

@@ -3,7 +3,7 @@
if (extension_loaded('pdo')) { if (extension_loaded('pdo')) {
/*abstract*/ class Min_PDO { /*abstract*/ class Min_PDO {
var $_result, $server_info, $affected_rows, $errno, $error, $pdo; var $_result, $server_info, $affected_rows, $errno, $error, $pdo;
function __construct() { function __construct() {
global $adminer; global $adminer;
$pos = array_search("SQL", $adminer->operators); $pos = array_search("SQL", $adminer->operators);
@@ -11,10 +11,10 @@ if (extension_loaded('pdo')) {
unset($adminer->operators[$pos]); unset($adminer->operators[$pos]);
} }
} }
function dsn($dsn, $username, $password, $options = array()) { function dsn($dsn, $username, $password, $options = []) {
$options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT; $options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT;
$options[PDO::ATTR_STATEMENT_CLASS] = array('Min_PDOStatement'); $options[PDO::ATTR_STATEMENT_CLASS] = [Min_PDOStatement::class];
try { try {
$this->pdo = new PDO($dsn, $username, $password, $options); $this->pdo = new PDO($dsn, $username, $password, $options);
} catch (Exception $ex) { } catch (Exception $ex) {
@@ -22,13 +22,13 @@ if (extension_loaded('pdo')) {
} }
$this->server_info = @$this->pdo->getAttribute(PDO::ATTR_SERVER_VERSION); $this->server_info = @$this->pdo->getAttribute(PDO::ATTR_SERVER_VERSION);
} }
/*abstract function select_db($database);*/ /*abstract function select_db($database);*/
function quote($string) { function quote($string) {
return $this->pdo->quote($string); return $this->pdo->quote($string);
} }
function query($query, $unbuffered = false) { function query($query, $unbuffered = false) {
$result = $this->pdo->query($query); $result = $this->pdo->query($query);
$this->error = ""; $this->error = "";
@@ -42,11 +42,11 @@ if (extension_loaded('pdo')) {
$this->store_result($result); $this->store_result($result);
return $result; return $result;
} }
function multi_query($query) { function multi_query($query) {
return $this->_result = $this->query($query); return $this->_result = $this->query($query);
} }
function store_result($result = null) { function store_result($result = null) {
if (!$result) { if (!$result) {
$result = $this->_result; $result = $this->_result;
@@ -61,7 +61,7 @@ if (extension_loaded('pdo')) {
$this->affected_rows = $result->rowCount(); $this->affected_rows = $result->rowCount();
return true; return true;
} }
function next_result() { function next_result() {
if (!$this->_result) { if (!$this->_result) {
return false; return false;
@@ -69,7 +69,7 @@ if (extension_loaded('pdo')) {
$this->_result->_offset = 0; $this->_result->_offset = 0;
return @$this->_result->nextRowset(); // @ - PDO_PgSQL doesn't support it return @$this->_result->nextRowset(); // @ - PDO_PgSQL doesn't support it
} }
function result($query, $field = 0) { function result($query, $field = 0) {
$result = $this->query($query); $result = $this->query($query);
if (!$result) { if (!$result) {
@@ -79,18 +79,18 @@ if (extension_loaded('pdo')) {
return $row[$field]; return $row[$field];
} }
} }
class Min_PDOStatement extends PDOStatement { class Min_PDOStatement extends PDOStatement {
var $_offset = 0, $num_rows; var $_offset = 0, $num_rows;
function fetch_assoc() { function fetch_assoc() {
return $this->fetch(PDO::FETCH_ASSOC); return $this->fetch(PDO::FETCH_ASSOC);
} }
function fetch_row() { function fetch_row() {
return $this->fetch(PDO::FETCH_NUM); return $this->fetch(PDO::FETCH_NUM);
} }
function fetch_field() { function fetch_field() {
$row = (object) $this->getColumnMeta($this->_offset++); $row = (object) $this->getColumnMeta($this->_offset++);
$row->orgtable = $row->table; $row->orgtable = $row->table;