PEAR:DB pgsql connecting to servers on alternate ports
| From: | Jeremy Maziarz | Date: | Thu, 27 Sep 2001 19:32:24 +0000 |
| Subject: | PEAR:DB pgsql connecting to servers on alternate ports | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-339@lists.php.net to get a copy of this message | ||
I stumbled onto this bug yesterday as I was trying to setup a PostGreSQL
server on a port other than the default (5432). No matter what I did
DB:connect would not connect, I kept getting the error:
DB Error: connect failed
To make a long story short, I poked around with DB/pgsql.php and found
two problems. Both of them are in the 'connect' function:
*** pgsql.php.orig Wed Sep 26 16:51:44 2001
--- pgsql.php Thu Sep 27 15:18:22 2001
***************
*** 84,97 ****
$protocol = (isset($dsninfo['protocol'])) ?
$dsninfo['protocol'] : '';
$connstr = '';
if (($host !== false) && ($protocol != 'unix')){
! if (($pos = strpos(':', $host)) !== false) {
$dbhost = substr($host, 0, $pos);
$port = substr($host, $pos + 1);
} else {
$dbhost = $host;
$port = '5432';
}
! $connstr = 'host=' . $dsninfo['hostspec'] . ' port=' .
$port;
}
if (isset($dsninfo['database'])) {
--- 84,97 ----
$protocol = (isset($dsninfo['protocol'])) ?
$dsninfo['protocol'] : '';
$connstr = '';
if (($host !== false) && ($protocol != 'unix')){
! if (($pos = strpos($host, ':')) !== false) {
$dbhost = substr($host, 0, $pos);
$port = substr($host, $pos + 1);
} else {
$dbhost = $host;
$port = '5432';
}
! $connstr = 'host=' . $dbhost . ' port=' . $port;
}
if (isset($dsninfo['database'])) {
1. The syntax for strpos is wrong (backwards); host:port is never parsed
correctly
2. The if/else was in essence ignored because the $connstr set 'host='
to $dnsinfo['hostspec'] instead of $dbhost
I searched the archives and a few other places and found no reference to
this bug anywhere. I find it hard to believe no one else has tried to
connect to a port other than the default. In any case, here it is.
-Jeremy
Email: jer2475@home.com