aboutsummaryrefslogtreecommitdiffstats
path: root/include/dba/dba_pdo.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2018-03-09 11:12:18 +0100
committerMario <mario@mariovavti.com>2018-03-09 11:12:18 +0100
commit4baf5eab16d809977a44e7911ddcab0ff8383897 (patch)
tree393f618c4cfc20f53264ecd8a26a08de0823d35d /include/dba/dba_pdo.php
parent577da0eb9eb1f90a4cf7a70cfb3582cfb49007ac (diff)
parent7361af85b5488fc8bd1744389a3a332dc74276b0 (diff)
downloadvolse-hubzilla-3.2.tar.gz
volse-hubzilla-3.2.tar.bz2
volse-hubzilla-3.2.zip
Merge branch '3.2RC'3.2
Diffstat (limited to 'include/dba/dba_pdo.php')
-rwxr-xr-xinclude/dba/dba_pdo.php56
1 files changed, 41 insertions, 15 deletions
diff --git a/include/dba/dba_pdo.php b/include/dba/dba_pdo.php
index f119d8926..f24c5381a 100755
--- a/include/dba/dba_pdo.php
+++ b/include/dba/dba_pdo.php
@@ -1,23 +1,30 @@
-<?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,':;')) {
$dsn = $server;
}
else {
- $dsn = $this->driver_dbtype . ':host=' . $server . (intval($port) ? '' : ';port=' . $port);
+ $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;
@@ -50,14 +66,15 @@ class dba_pdo extends dba_driver {
}
}
+ $result = null;
$this->error = '';
- $select = ((stripos($sql,'select') === 0) ? true : false);
+ $select = ((stripos($sql, 'select') === 0) ? true : false);
try {
$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 +99,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 +115,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 . '\')';
@@ -111,6 +128,15 @@ class dba_pdo extends dba_driver {
}
}
+ function use_index($str) {
+ if($this->driver_dbtype === 'pgsql') {
+ return '';
+ }
+ else {
+ return 'USE INDEX( ' . $str . ')';
+ }
+ }
+
function quote_interval($txt) {
if($this->driver_dbtype === 'pgsql') {
return "'$txt'";
@@ -131,7 +157,7 @@ class dba_pdo extends dba_driver {
return $this->escape($str);
}
}
-
+
function unescapebin($str) {
if($this->driver_dbtype === 'pgsql' && (! is_null($str))) {
$x = '';
@@ -154,4 +180,4 @@ class dba_pdo extends dba_driver {
return 'pdo';
}
-} \ No newline at end of file
+}