- if (PEAR::isError($oSql)) {
- fail($sMsg || $oSql->getMessage(), $oSql->userinfo);
+ // Convert database DSN to psql parameters
+ $aDSNInfo = \Nominatim\DB::parseDSN(CONST_Database_DSN);
+ if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) $aDSNInfo['port'] = 5432;
+
+ $oCmd = new \Nominatim\Shell('psql');
+ $oCmd->addParams('--port', $aDSNInfo['port']);
+ $oCmd->addParams('--dbname', $aDSNInfo['database']);
+ if (isset($aDSNInfo['hostspec']) && $aDSNInfo['hostspec']) {
+ $oCmd->addParams('--host', $aDSNInfo['hostspec']);
+ }
+ if (isset($aDSNInfo['username']) && $aDSNInfo['username']) {
+ $oCmd->addParams('--username', $aDSNInfo['username']);
+ }
+ if (isset($aDSNInfo['password'])) {
+ $oCmd->addEnvPair('PGPASSWORD', $aDSNInfo['password']);
+ }
+ if (!$bVerbose) {
+ $oCmd->addParams('--quiet');
+ }
+ if ($bfatal && !$bIgnoreErrors) {
+ $oCmd->addParams('-v', 'ON_ERROR_STOP=1');