#39382, postgres db connection ... eliminate warnings, backport from head

4.7.x
Gerhard Killesreiter 2006-10-12 20:01:49 +00:00
parent 3633f23d3a
commit 81d07c0de9
1 changed files with 16 additions and 7 deletions

View File

@ -31,15 +31,24 @@ function db_connect($url) {
}
$url = parse_url($url);
$conn_string = '';
// Decode url-encoded information in the db connection string
$url['user'] = urldecode($url['user']);
$url['pass'] = urldecode($url['pass']);
$url['host'] = urldecode($url['host']);
$url['path'] = urldecode($url['path']);
$conn_string = ' user='. $url['user'] .' dbname='. substr($url['path'], 1) .' password='. $url['pass'] . ' host=' . $url['host'];
$conn_string .= isset($url['port']) ? ' port=' . $url['port'] : '';
if (isset($url['user'])) {
$conn_string .= ' user=' . urldecode($url['user']);
}
if (isset($url['pass'])) {
$conn_string .= ' password=' . urldecode($url['pass']);
}
if (isset($url['host'])) {
$conn_string .= ' host=' . urldecode($url['host']);
}
if (isset($url['path'])) {
$conn_string .= ' dbname=' . substr(urldecode($url['path']), 1);
}
if (isset($url['port'])) {
$conn_string .= ' port=' . urldecode($url['port']);
}
// pg_last_error() does not return a useful error message for database
// connection errors. We must turn on error tracking to get at a good error