Re: PEAR:DB pgsql connecting to servers on alternate ports
| From: | Markus Fischer | Date: | Thu, 27 Sep 2001 20:08:30 +0000 |
| Subject: | Re: PEAR:DB pgsql connecting to servers on alternate ports | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-340@lists.php.net to get a copy of this message | ||
Somehow the code looks odd to me anyway (not want to offend
anyone!). I mean .. using strpos, substr, substr, etc.
What about:
list($dbhost,$dbport) = explode(':', $host);
$dbport = ( (is_null($db_port) ? '5432' : $db_port));
Smaller and easier to read.
- Markus
On Thu, Sep 27, 2001 at 03:32:24PM -0400, Jeremy Maziarz wrote :
> 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
>
>
>
> --
> PEAR General Mailing List (http://pear.php.net/)
> To unsubscribe, e-mail: pear-general-unsubscribe@lists.php.net
> For additional commands, e-mail: pear-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
--
Markus Fischer, http://guru.josefine.at/~mfischer/
EMail: mfischer@guru.josefine.at
PGP Public Key: http://guru.josefine.at/~mfischer/C2272BD0.asc
PGP Fingerprint: D3B0 DD4F E12B F911 3CE1 C2B5 D674 B445 C227 2BD0
-All your scripts are belong to Zend-