use pdo for postgres also
This commit is contained in:
parent
2702b82bc3
commit
3726b546d5
@ -54,7 +54,7 @@ class DBA {
|
|||||||
self::$scheme = 'postgres';
|
self::$scheme = 'postgres';
|
||||||
|
|
||||||
require_once('include/dba/dba_postgres.php');
|
require_once('include/dba/dba_postgres.php');
|
||||||
self::$dba = new dba_postgres($server, $port, $user, $pass, $db, $install);
|
self::$dba = new dba_postgres($server, self::$scheme, $port, $user, $pass, $db, $install);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(!($port))
|
if(!($port))
|
||||||
@ -63,8 +63,7 @@ class DBA {
|
|||||||
$server = '127.0.0.1';
|
$server = '127.0.0.1';
|
||||||
|
|
||||||
require_once('include/dba/dba_pdo.php');
|
require_once('include/dba/dba_pdo.php');
|
||||||
self::$dba = new dba_pdo($server,$port,$user,$pass,$db,$install);
|
self::$dba = new dba_pdo($server,self::$scheme,$port,$user,$pass,$db,$install);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -112,7 +111,7 @@ abstract class dba_driver {
|
|||||||
* @param string $db database name
|
* @param string $db database name
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
abstract function connect($server, $port, $user, $pass, $db);
|
abstract function connect($server, $scheme, $port, $user, $pass, $db);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Perform a DB query with the SQL statement $sql.
|
* @brief Perform a DB query with the SQL statement $sql.
|
||||||
@ -146,31 +145,31 @@ abstract class dba_driver {
|
|||||||
*/
|
*/
|
||||||
abstract function getdriver();
|
abstract function getdriver();
|
||||||
|
|
||||||
function __construct($server, $port, $user,$pass,$db,$install = false) {
|
function __construct($server, $scheme, $port, $user,$pass,$db,$install = false) {
|
||||||
if(($install) && (! $this->install($server, $port, $user, $pass, $db))) {
|
if(($install) && (! $this->install($server, $scheme, $port, $user, $pass, $db))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->connect($server, $port, $user, $pass, $db);
|
$this->connect($server, $scheme, $port, $user, $pass, $db);
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_null_date() {
|
function get_null_date() {
|
||||||
return DBA::$null_date;
|
return \DBA::$null_date;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_install_script() {
|
function get_install_script() {
|
||||||
return DBA::$install_script;
|
return \DBA::$install_script;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_table_quote() {
|
function get_table_quote() {
|
||||||
return DBA::$tquot;
|
return \DBA::$tquot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function utcnow() {
|
function utcnow() {
|
||||||
return DBA::$utc_now;
|
return \DBA::$utc_now;
|
||||||
}
|
}
|
||||||
|
|
||||||
function install($server,$user,$pass,$db) {
|
function install($server,$scheme,$port,$user,$pass,$db) {
|
||||||
if (!(strlen($server) && strlen($user))){
|
if (!(strlen($server) && strlen($user))){
|
||||||
$this->connected = false;
|
$this->connected = false;
|
||||||
$this->db = null;
|
$this->db = null;
|
||||||
|
@ -5,7 +5,7 @@ require_once('include/dba/dba_driver.php');
|
|||||||
|
|
||||||
class dba_mysql extends dba_driver {
|
class dba_mysql extends dba_driver {
|
||||||
|
|
||||||
function connect($server, $port, $user,$pass,$db) {
|
function connect($server, $scheme, $port, $user,$pass,$db) {
|
||||||
$this->db = mysql_connect($server.":".$port,$user,$pass);
|
$this->db = mysql_connect($server.":".$port,$user,$pass);
|
||||||
if($this->db && mysql_select_db($db,$this->db)) {
|
if($this->db && mysql_select_db($db,$this->db)) {
|
||||||
$this->connected = true;
|
$this->connected = true;
|
||||||
|
@ -4,7 +4,7 @@ require_once('include/dba/dba_driver.php');
|
|||||||
|
|
||||||
class dba_mysqli extends dba_driver {
|
class dba_mysqli extends dba_driver {
|
||||||
|
|
||||||
function connect($server,$port,$user,$pass,$db) {
|
function connect($server,$scheme,$port,$user,$pass,$db) {
|
||||||
if($port)
|
if($port)
|
||||||
$this->db = new mysqli($server,$user,$pass,$db, $port);
|
$this->db = new mysqli($server,$user,$pass,$db, $port);
|
||||||
else
|
else
|
||||||
|
@ -7,9 +7,9 @@ class dba_pdo extends dba_driver {
|
|||||||
|
|
||||||
public $driver_dbtype = null;
|
public $driver_dbtype = null;
|
||||||
|
|
||||||
function connect($server,$port,$user,$pass,$db) {
|
function connect($server,$scheme,$port,$user,$pass,$db) {
|
||||||
|
|
||||||
$this->driver_dbtype = 'mysql';
|
$this->driver_dbtype = $scheme;
|
||||||
$dns = $this->driver_dbtype
|
$dns = $this->driver_dbtype
|
||||||
. ':host=' . $server . (is_null($port) ? '' : ';port=' . $port)
|
. ':host=' . $server . (is_null($port) ? '' : ';port=' . $port)
|
||||||
. ';dbname=' . $db;
|
. ';dbname=' . $db;
|
||||||
@ -28,6 +28,9 @@ class dba_pdo extends dba_driver {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($this->driver_dbtype === 'postgres')
|
||||||
|
$this->q("SET standard_conforming_strings = 'off'; SET backslash_quote = 'on';");
|
||||||
|
|
||||||
$this->connected = true;
|
$this->connected = true;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -37,6 +40,9 @@ class dba_pdo extends dba_driver {
|
|||||||
if((! $this->db) || (! $this->connected))
|
if((! $this->db) || (! $this->connected))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if($this->driver_dbtype === 'postgres' && (! strpos($sql,';')))
|
||||||
|
$sql .= ';';
|
||||||
|
|
||||||
$this->error = '';
|
$this->error = '';
|
||||||
$select = ((stripos($sql,'select') === 0) ? true : false);
|
$select = ((stripos($sql,'select') === 0) ? true : false);
|
||||||
|
|
||||||
@ -89,6 +95,16 @@ class dba_pdo extends dba_driver {
|
|||||||
$this->connected = false;
|
$this->connected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function concat($fld,$sep) {
|
||||||
|
if($this->driver_dbtype === 'postgres') {
|
||||||
|
return 'string_agg(' . $fld . ',\'' . $sep . '\')';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 'GROUP_CONCAT(DISTINCT '.$fld.' SEPARATOR \''.$sep.'\')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function getdriver() {
|
function getdriver() {
|
||||||
return 'pdo';
|
return 'pdo';
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ class dba_postgres extends dba_driver {
|
|||||||
const UTC_NOW = "now() at time zone 'UTC'";
|
const UTC_NOW = "now() at time zone 'UTC'";
|
||||||
const TQUOT = '"';
|
const TQUOT = '"';
|
||||||
|
|
||||||
function connect($server,$port,$user,$pass,$db) {
|
function connect($server,$scheme,$port,$user,$pass,$db) {
|
||||||
if(!$port) $port = 5432;
|
if(!$port) $port = 5432;
|
||||||
$connstr = 'host=' . $server . ' port='.$port . ' user=' . $user . ' password=' . $pass . ' dbname='. $db;
|
$connstr = 'host=' . $server . ' port='.$port . ' user=' . $user . ' password=' . $pass . ' dbname='. $db;
|
||||||
$this->db = pg_connect($connstr);
|
$this->db = pg_connect($connstr);
|
||||||
|
Reference in New Issue
Block a user