pdo changes first cut

This commit is contained in:
zotlabs 2016-10-19 16:58:26 -07:00
parent c79c1b3913
commit aee4f8d2fe
2 changed files with 27 additions and 30 deletions

View File

@ -12,8 +12,16 @@ class DBA {
static public $dba = null; static public $dba = null;
static public $dbtype = null; static public $dbtype = null;
static public $scheme = 'mysql';
static public $logging = false; static public $logging = false;
static public $install_script = 'install/schema_mysql.sql';
static public $null_date = '0001-01-01 00:00:00';
static public $utc_now = 'UTC_TIMESTAMP()';
static public $tquot = "`";
/** /**
* @brief Returns the database driver object. * @brief Returns the database driver object.
* *
@ -35,50 +43,42 @@ class DBA {
self::$dbtype = intval($dbtype); self::$dbtype = intval($dbtype);
if(self::$dbtype == DBTYPE_POSTGRES) { if(self::$dbtype == DBTYPE_POSTGRES) {
if(! ($port)) if(!($port))
$port = 5432; $port = 5432;
self::$install_script = 'install/schema_postgres.sql';
self::$utc_now = "now() at time zone 'UTC'";
self::$tquot = '"';
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, $port, $user, $pass, $db, $install);
} }
else { else {
if(! ($port)) if(!($port))
$port = 3306; $port = 3306;
if($server === 'localhost') if($server === 'localhost')
$server = '127.0.0.1'; $server = '127.0.0.1';
require_once('include/dba/dba_pdo.php');
self::$dba = new dba_pdo($server,$port,$user,$pass,$db,$install);
// Highly experimental at the present time.
// require_once('include/dba/dba_pdo.php');
// self::$dba = new dba_pdo($server, $port,$user,$pass,$db,$install);
// }
if(class_exists('mysqli')) {
require_once('include/dba/dba_mysqli.php');
self::$dba = new dba_mysqli($server, $set_port,$user,$pass,$db,$install);
}
} }
// Until we have a proper PDO driver, store the DB connection parameters for
// plugins/addons which use PDO natively (such as cdav). This is wasteful as
// it opens a separate connection to the DB, but saves a lot of effort re-writing
// third-party interfaces that are working and well tested.
if(is_object(self::$dba) && self::$dba->connected) { if(is_object(self::$dba) && self::$dba->connected) {
if($server === 'localhost')
$port = $set_port;
$dns = ((self::$dbtype == DBTYPE_POSTGRES) ? 'postgres' : 'mysql') $dns = ((self::$dbtype == DBTYPE_POSTGRES) ? 'postgres' : 'mysql')
. ':host=' . $server . (is_null($port) ? '' : ';port=' . $port) . ':host=' . $server . (is_null($port) ? '' : ';port=' . $port)
. ';dbname=' . $db; . ';dbname=' . $db;
self::$dba->pdo_set(array($dns,$user,$pass)); self::$dba->pdo_set(array($dns,$user,$pass));
} }
define('NULL_DATE', self::$dba->get_null_date()); define('NULL_DATE', self::$null_date);
define('ACTIVE_DBTYPE', self::$dbtype); define('ACTIVE_DBTYPE', self::$dbtype);
define('TQUOT', self::$dba->get_table_quote()); define('TQUOT', self::$tquot);
return self::$dba; return self::$dba;
} }
@ -92,10 +92,6 @@ class DBA {
*/ */
abstract class dba_driver { abstract class dba_driver {
// legacy behavior // legacy behavior
const INSTALL_SCRIPT='install/schema_mysql.sql';
const NULL_DATE = '0001-01-01 00:00:00';
const UTC_NOW = 'UTC_TIMESTAMP()';
const TQUOT = "`";
protected $db; protected $db;
protected $pdo = array(); protected $pdo = array();
@ -158,20 +154,20 @@ abstract class dba_driver {
} }
function get_null_date() { function get_null_date() {
return static::NULL_DATE; return self::$null_date;
} }
function get_install_script() { function get_install_script() {
return static::INSTALL_SCRIPT; return self::$install_script;
} }
function get_table_quote() { function get_table_quote() {
return static::TQUOT; return self::$tquot;
} }
function utcnow() { function utcnow() {
return static::UTC_NOW; return self::$utc_now;
} }
function install($server,$user,$pass,$db) { function install($server,$user,$pass,$db) {

View File

@ -9,11 +9,12 @@ class dba_pdo extends dba_driver {
function connect($server,$port,$user,$pass,$db) { function connect($server,$port,$user,$pass,$db) {
$this->driver_dbtype = 'mysql'; // (($dbtype == DBTYPE_POSTGRES) ? 'postgres' : 'mysql'); $this->driver_dbtype = 'mysql';
$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;
db_logger('dns: ' . $dns);
try { try {
$this->db = new PDO($dns,$user,$pass); $this->db = new PDO($dns,$user,$pass);