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
}
/**
- * 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
*
*/
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;
}