aboutsummaryrefslogtreecommitdiffstats
path: root/include/dba/dba_pdo.php
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2016-10-25 11:48:22 +1100
committerGitHub <noreply@github.com>2016-10-25 11:48:22 +1100
commit2d2ac98b3d9a24e0601e22b0d6ed4b57f7071911 (patch)
tree8792f3a8fc16560261f658d90e952b348163a6be /include/dba/dba_pdo.php
parentf1fc2018626a5349000e666278571575f95a7acc (diff)
parent5dc8c54b8d3bd696095788704d4f8f8228c53522 (diff)
downloadvolse-hubzilla-2d2ac98b3d9a24e0601e22b0d6ed4b57f7071911.tar.gz
volse-hubzilla-2d2ac98b3d9a24e0601e22b0d6ed4b57f7071911.tar.bz2
volse-hubzilla-2d2ac98b3d9a24e0601e22b0d6ed4b57f7071911.zip
Merge pull request #559 from zotlabs/pdo
Pdo DB driver
Diffstat (limited to 'include/dba/dba_pdo.php')
-rwxr-xr-xinclude/dba/dba_pdo.php74
1 files changed, 68 insertions, 6 deletions
diff --git a/include/dba/dba_pdo.php b/include/dba/dba_pdo.php
index 7255a2b66..b247728ff 100755
--- a/include/dba/dba_pdo.php
+++ b/include/dba/dba_pdo.php
@@ -7,16 +7,21 @@ class dba_pdo extends dba_driver {
public $driver_dbtype = null;
- function connect($server,$port,$user,$pass,$db) {
+ function connect($server,$scheme,$port,$user,$pass,$db) {
- $this->driver_dbtype = 'mysql'; // (($dbtype == DBTYPE_POSTGRES) ? 'postgres' : 'mysql');
- $dns = $this->driver_dbtype
- . ':host=' . $server . (is_null($port) ? '' : ';port=' . $port)
- . ';dbname=' . $db;
+ $this->driver_dbtype = $scheme;
+ if(strpbrk($server,':;')) {
+ $dsn = $server;
+ }
+ else {
+ $dsn = $this->driver_dbtype . ':host=' . $server . (is_null($port) ? '' : ';port=' . $port);
+ }
+
+ $dsn .= ';dbname=' . $db;
try {
- $this->db = new PDO($dns,$user,$pass);
+ $this->db = new PDO($dsn,$user,$pass);
$this->db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e) {
@@ -27,6 +32,9 @@ class dba_pdo extends dba_driver {
return false;
}
+ if($this->driver_dbtype === 'pgsql')
+ $this->q("SET standard_conforming_strings = 'off'; SET backslash_quote = 'on';");
+
$this->connected = true;
return true;
@@ -36,6 +44,12 @@ class dba_pdo extends dba_driver {
if((! $this->db) || (! $this->connected))
return false;
+ if($this->driver_dbtype === 'pgsql') {
+ if(substr(rtrim($sql),-1,1) !== ';') {
+ $sql .= ';';
+ }
+ }
+
$this->error = '';
$select = ((stripos($sql,'select') === 0) ? true : false);
@@ -88,6 +102,54 @@ class dba_pdo extends dba_driver {
$this->connected = false;
}
+ function concat($fld,$sep) {
+ if($this->driver_dbtype === 'pgsql') {
+ return 'string_agg(' . $fld . ',\'' . $sep . '\')';
+ }
+ else {
+ return 'GROUP_CONCAT(DISTINCT ' . $fld . ' SEPARATOR \'' . $sep . '\')';
+ }
+ }
+
+ function quote_interval($txt) {
+ if($this->driver_dbtype === 'pgsql') {
+ return "'$txt'";
+ }
+ else {
+ return $txt;
+ }
+ }
+
+ // These two functions assume that postgres standard_conforming_strings is set to off;
+ // which we perform during DB open.
+
+ function escapebin($str) {
+ if($this->driver_dbtype === 'pgsql') {
+ return "\\\\x" . bin2hex($str);
+ }
+ else {
+ return $this->escape($str);
+ }
+ }
+
+ function unescapebin($str) {
+ if($this->driver_dbtype === 'pgsql') {
+ $x = '';
+ while(! feof($str)) {
+ $x .= fread($str,8192);
+ }
+ if(substr($x,0,2) === '\\x') {
+ $x = hex2bin(substr($x,2));
+ }
+ return $x;
+
+ }
+ else {
+ return $str;
+ }
+ }
+
+
function getdriver() {
return 'pdo';
}