X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/38c21de0ee17bb0eacd6cc8f0e1ed71cbee0b0c9..a759c5b75b66894b1902327097185840a2557f86:/lib/DB.php diff --git a/lib/DB.php b/lib/DB.php index 5915b2e8..0454a0ff 100644 --- a/lib/DB.php +++ b/lib/DB.php @@ -2,7 +2,7 @@ namespace Nominatim; -require_once(CONST_BasePath.'/lib/DatabaseError.php'); +require_once(CONST_LibDir.'/DatabaseError.php'); /** * Uses PDO to access the database specified in the CONST_Database_DSN @@ -12,9 +12,9 @@ class DB { protected $connection; - public function __construct($sDSN = CONST_Database_DSN) + public function __construct($sDSN = null) { - $this->sDSN = $sDSN; + $this->sDSN = $sDSN ?? getSetting('DATABASE_DSN'); } public function connect($bNew = false, $bPersistent = true) @@ -251,7 +251,7 @@ class DB } /** - * Deletes a table. Returns true on success. Returns true if the table didn't exist. + * Deletes a table. Returns true if deleted or didn't exist. * * @param string $sTableName * @@ -405,29 +405,16 @@ END; */ public static function generateDSN($aInfo) { - $sDSN = 'pgsql:'; - if (isset($aInfo['host'])) { - $sDSN .= 'host=' . $aInfo['host'] . ';'; - } elseif (isset($aInfo['hostspec'])) { - $sDSN .= 'host=' . $aInfo['hostspec'] . ';'; - } - if (isset($aInfo['port'])) { - $sDSN .= 'port=' . $aInfo['port'] . ';'; - } - if (isset($aInfo['dbname'])) { - $sDSN .= 'dbname=' . $aInfo['dbname'] . ';'; - } elseif (isset($aInfo['database'])) { - $sDSN .= 'dbname=' . $aInfo['database'] . ';'; - } - if (isset($aInfo['user'])) { - $sDSN .= 'user=' . $aInfo['user'] . ';'; - } elseif (isset($aInfo['username'])) { - $sDSN .= 'user=' . $aInfo['username'] . ';'; - } - if (isset($aInfo['password'])) { - $sDSN .= 'password=' . $aInfo['password'] . ';'; - } - $sDSN = preg_replace('/;$/', '', $sDSN); + $sDSN = sprintf( + 'pgsql:host=%s;port=%s;dbname=%s;user=%s;password=%s;', + $aInfo['host'] ?? $aInfo['hostspec'] ?? '', + $aInfo['port'] ?? '', + $aInfo['dbname'] ?? $aInfo['database'] ?? '', + $aInfo['user'] ?? '', + $aInfo['password'] ?? '' + ); + $sDSN = preg_replace('/\b\w+=;/', '', $sDSN); + $sDSN = preg_replace('/;\Z/', '', $sDSN); return $sDSN; }