aboutsummaryrefslogtreecommitdiffstats
path: root/include/dba/dba_driver.php
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2016-10-20 17:04:43 -0700
committerzotlabs <mike@macgirvin.com>2016-10-20 17:04:43 -0700
commit04ac04e0ada6b8dbe3f512379abd2859eb758173 (patch)
tree2a61195efe29fc47a1f88985b361806fc3e68f0a /include/dba/dba_driver.php
parent29340152b6a924a27dc62363d623e3dd287b5a2a (diff)
downloadvolse-hubzilla-04ac04e0ada6b8dbe3f512379abd2859eb758173.tar.gz
volse-hubzilla-04ac04e0ada6b8dbe3f512379abd2859eb758173.tar.bz2
volse-hubzilla-04ac04e0ada6b8dbe3f512379abd2859eb758173.zip
allow a dsn override to the database via the server argument. This could be used to allow unix domain sockets and other unusual configurations.
Diffstat (limited to 'include/dba/dba_driver.php')
-rwxr-xr-xinclude/dba/dba_driver.php22
1 files changed, 12 insertions, 10 deletions
diff --git a/include/dba/dba_driver.php b/include/dba/dba_driver.php
index e8c79045b..b4cda6d8e 100755
--- a/include/dba/dba_driver.php
+++ b/include/dba/dba_driver.php
@@ -25,16 +25,14 @@ class DBA {
/**
* @brief Returns the database driver object.
*
- * If available it will use PHP's mysqli otherwise mysql driver.
- *
- * @param string $server DB server name
+ * @param string $server DB server name (or PDO dsn - e.g. mysqli:foobar.com;)
* @param string $port DB port
* @param string $user DB username
* @param string $pass DB password
* @param string $db database name
* @param string $dbtype 0 for mysql, 1 for postgres
* @param bool $install Defaults to false
- * @return null|dba_driver A database driver object (dba_mysql|dba_mysqli) or null if no driver found.
+ * @return null|dba_driver A database driver object (dba_pdo) or null if no driver found.
*/
static public function dba_factory($server,$port,$user,$pass,$db,$dbtype,$install = false) {
@@ -57,8 +55,6 @@ class DBA {
else {
if(!($port))
$port = 3306;
- if($server === 'localhost')
- $server = '127.0.0.1';
}
require_once('include/dba/dba_pdo.php');
@@ -66,10 +62,16 @@ class DBA {
if(is_object(self::$dba) && self::$dba->connected) {
- $dns = ((self::$dbtype == DBTYPE_POSTGRES) ? 'pgsql' : 'mysql')
- . ':host=' . $server . (is_null($port) ? '' : ';port=' . $port)
- . ';dbname=' . $db;
- self::$dba->pdo_set(array($dns,$user,$pass));
+ if(strpbrk($server,':;')) {
+ $dsn = $server;
+ }
+ else {
+ $dsn = self::$scheme . ':host=' . $server . (is_null($port) ? '' : ';port=' . $port);
+ }
+ $dsn .= ';dbname=' . $db;
+
+
+ self::$dba->pdo_set(array($dsn,$user,$pass));
}
define('NULL_DATE', self::$null_date);