aboutsummaryrefslogtreecommitdiffstats
path: root/include/dba/dba_pdo.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/dba/dba_pdo.php')
-rwxr-xr-xinclude/dba/dba_pdo.php51
1 files changed, 49 insertions, 2 deletions
diff --git a/include/dba/dba_pdo.php b/include/dba/dba_pdo.php
index 7255a2b66..bb89df6be 100755
--- a/include/dba/dba_pdo.php
+++ b/include/dba/dba_pdo.php
@@ -7,13 +7,14 @@ 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');
+ $this->driver_dbtype = $scheme;
$dns = $this->driver_dbtype
. ':host=' . $server . (is_null($port) ? '' : ';port=' . $port)
. ';dbname=' . $db;
+ // db_logger('dns: ' . $dns);
try {
$this->db = new PDO($dns,$user,$pass);
@@ -27,6 +28,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 +40,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 +98,43 @@ 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;
+ }
+ }
+
+ function escapebin($str) {
+ if($this->driver_dbtype === 'pgsql') {
+ return str_replace([ chr(92), chr(0), chr(39) ], [ '\\\134', '\\\000', '\\\047' ], $str);
+ }
+ else {
+ return $this->escape($str);
+ }
+ }
+
+ function unescapebin($str) {
+ if($this->driver_dbtype === 'pgsql') {
+ return stripcslashes($str);
+ }
+ else {
+ return $str;
+ }
+ }
+
+
function getdriver() {
return 'pdo';
}