diff options
author | Klaus Weidenbach <Klaus.Weidenbach@gmx.net> | 2017-12-08 00:26:00 +0100 |
---|---|---|
committer | Klaus Weidenbach <Klaus.Weidenbach@gmx.net> | 2018-01-28 23:02:15 +0100 |
commit | 509844fd7e08ebccec4d924845d0f2a60f5768e5 (patch) | |
tree | b74df0038713c1ab4570ab03ebe1c238085c8905 /include/dba/dba_pdo.php | |
parent | fb111e6d958fdf56352db66e144134241abbacf8 (diff) | |
download | volse-hubzilla-509844fd7e08ebccec4d924845d0f2a60f5768e5.tar.gz volse-hubzilla-509844fd7e08ebccec4d924845d0f2a60f5768e5.tar.bz2 volse-hubzilla-509844fd7e08ebccec4d924845d0f2a60f5768e5.zip |
:fire: Cleanup old database related files.
Remove non used database drivers, remove unused methods.
Improve documentation.
Diffstat (limited to 'include/dba/dba_pdo.php')
-rwxr-xr-x | include/dba/dba_pdo.php | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/include/dba/dba_pdo.php b/include/dba/dba_pdo.php index a9d824a50..719f23c4b 100755 --- a/include/dba/dba_pdo.php +++ b/include/dba/dba_pdo.php @@ -1,14 +1,21 @@ -<?php /** @file */ +<?php -require_once('include/dba/dba_driver.php'); +require_once 'include/dba/dba_driver.php'; +/** + * @brief PDO based database driver. + * + */ class dba_pdo extends dba_driver { - public $driver_dbtype = null; - function connect($server,$scheme,$port,$user,$pass,$db) { - + /** + * {@inheritDoc} + * @see dba_driver::connect() + */ + function connect($server, $scheme, $port, $user, $pass, $db) { + $this->driver_dbtype = $scheme; if(strpbrk($server,':;')) { @@ -17,7 +24,7 @@ class dba_pdo extends dba_driver { else { $dsn = $this->driver_dbtype . ':host=' . $server . (intval($port) ? ';port=' . $port : ''); } - + $dsn .= ';dbname=' . $db; try { @@ -36,10 +43,19 @@ class dba_pdo extends dba_driver { $this->q("SET standard_conforming_strings = 'off'; SET backslash_quote = 'on';"); $this->connected = true; - return true; + return true; } + /** + * {@inheritDoc} + * @see dba_driver::q() + * + * @return bool|array|PDOStatement + * - \b false if not connected or PDOException occured on query + * - \b array with results on a SELECT query + * - \b PDOStatement on a non SELECT SQL query + */ function q($sql) { if((! $this->db) || (! $this->connected)) return false; @@ -57,7 +73,7 @@ class dba_pdo extends dba_driver { $result = $this->db->query($sql, PDO::FETCH_ASSOC); } catch(PDOException $e) { - + $this->error = $e->getMessage(); if($this->error) { db_logger('dba_pdo: ERROR: ' . printable($sql) . "\n" . $this->error, LOGGER_NORMAL, LOG_ERR); @@ -82,11 +98,10 @@ class dba_pdo extends dba_driver { } if($this->debug) { - db_logger('dba_pdo: DEBUG: ' . printable($sql) . ' returned ' . count($r) . ' results.', LOGGER_NORMAL, LOG_INFO); + db_logger('dba_pdo: DEBUG: ' . printable($sql) . ' returned ' . count($r) . ' results.', LOGGER_NORMAL, LOG_INFO); db_logger('dba_pdo: ' . printable(print_r($r,true)), LOGGER_NORMAL, LOG_INFO); } - return (($this->error) ? false : $r); } @@ -99,9 +114,10 @@ class dba_pdo extends dba_driver { function close() { if($this->db) $this->db = null; + $this->connected = false; } - + function concat($fld,$sep) { if($this->driver_dbtype === 'pgsql') { return 'string_agg(' . $fld . ',\'' . $sep . '\')'; @@ -140,7 +156,7 @@ class dba_pdo extends dba_driver { return $this->escape($str); } } - + function unescapebin($str) { if($this->driver_dbtype === 'pgsql' && (! is_null($str))) { $x = ''; |