commit 4b5cf966691aea9021b5953a12e8373cdc79a8bb
parent 9cb666660d29b7d0709c3f8265f058bb24bccdd7
Author: Jan Dankert <develop@jandankert.de>
Date: Fri, 23 Oct 2020 11:25:21 +0200
Database connection: Adding the TCP-Port, Support for SQLITE.
Diffstat:
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/modules/database/driver/PDODriver.class.php b/modules/database/driver/PDODriver.class.php
@@ -74,12 +74,20 @@ class PDODriver
if (!in_array($driver,PDO::getAvailableDrivers(),TRUE))
throw new DatabaseException('PDO driver '.$driver.' is not available');
- $dsn = [
- $driver.':host' => $conf['host' ],
- 'dbname' => $conf['database'],
- 'charset' => $conf['charset' ]
- ];
-
+ $dsn = [];
+ if ( $conf['host'] )
+ $dsn[ $driver.':host' ] = $conf['host']; // Hostname for RDBMS with IP-stack
+ elseif ( $conf['file'] )
+ $dsn[ $driver.':'.$conf['file'] ] = $conf['host']; // Filename for SQLITE
+
+ if ( $conf['database'] )
+ $dsn['dbname' ] = $conf['database'];
+ if ( $conf['port'] )
+ $dsn['port' ] = $conf['port'];
+ if ( $conf['charset'] )
+ $dsn['charset'] = $conf['charset' ];
+
+ // Building the DSN for PDO.
$url = implode('; ',array_map( function($key,$value) {
return $key.'='.$value;
},array_keys($dsn),$dsn));