mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-20 01:35:12 +00:00
allow a dsn override to the database via the server argument. This could be used to allow unix domain sockets and other unusual configurations.
This commit is contained in:
parent
29340152b6
commit
04ac04e0ad
2 changed files with 21 additions and 15 deletions
|
@ -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);
|
||||
|
|
|
@ -10,14 +10,18 @@ class dba_pdo extends dba_driver {
|
|||
function connect($server,$scheme,$port,$user,$pass,$db) {
|
||||
|
||||
$this->driver_dbtype = $scheme;
|
||||
$dns = $this->driver_dbtype
|
||||
. ':host=' . $server . (is_null($port) ? '' : ';port=' . $port)
|
||||
. ';dbname=' . $db;
|
||||
|
||||
// db_logger('dns: ' . $dns);
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue