Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.12.2

Bug #339 DB::PGSQL doesn't recognize sockets for a pgsql connection
Submitted: 2003-12-03 08:14 UTC
From: t dot rietsch at nzz dot ch Assigned: chagenbu
Status: Closed Package: DB
PHP Version: Irrelevant OS: all
Roadmaps: (Not assigned)    
Subscription  


 [2003-12-03 08:14 UTC] t dot rietsch at nzz dot ch
Description: ------------ The PEAR DB::PGSQL Package doesn't use sockets. In the code of the DB/pgsql.php on the line 83, it checks against protcol tcp but not against protocol unix, which describes a socket connection: Line 83: if ($protocol == 'tcp') {....} If a user configured his system to create the socket not in the default place (/tmp), pear isn't able to connect over the socket to the database, because pg_connect (php) or the PGconnectdb (libpq from postgresql) tries to open /tmp/SOCKET. The problem can be solved, if you put the place of the SOCKET in the hostname filed of the connection string (host=PATH_TO_SOCKET_FOLDER). This is described in the PostgreSQL Documentation: http://www.postgresql.org/docs/current/interactive/libpq.html#LIBPQ-CONNECT Here is a suggestion for a workaround: ---------------- CODE ---------------------- FILE: DB/pgsql.php 83 if ($protocol == 'tcp') { 84 if (!empty($dsninfo['hostspec'])) { 85 $connstr = 'host=' . $dsninfo['hostspec']; 86 } 87 if (!empty($dsninfo['port'])) { 88 $connstr .= ' port=' . $dsninfo['port']; 89 } 90 } + 91 else if ($protocol == 'unix') { + 92 if (!empty($dsninfo['hostsepc'])) { + 93 $connstr = 'host=' . $dsninfo['hostspec']; + 94 } + 95 } ---------------- CODE ---------------------- Perhaps you're going to fix this in the future. Thanks for your work Thierry

Comments

 [2003-12-03 11:28 UTC] t dot rietsch at nzz dot ch
Sorry I have published a wrong line for Line 93: $connstr = 'host=' . $dsninfo['socket']; <= This is correct, not dnsinfo['hostspec']; Sorry for my failure thierry
 [2003-12-18 19:09 UTC] chagenbu at php dot net
This bug has been fixed in CVS. In case this was a documentation problem, the fix will show up at the end of next Sunday (CET) on pear.php.net. In case this was a pear.php.net website problem, the change will show up on the website in short time. Thank you for the report, and for helping us make PEAR better.
 [2006-12-23 20:32 UTC] cellog (Greg Beaver)
assign to fixer
 [2007-02-21 07:30 UTC] spam at me dot not (SpamMeNot)
The PEAR DB::PGSQL package does support sockets now. Just put path to the socket in DSN like this: pgsql://username:password@localhost(/pathtosocket)/database But if you don't want to use sockets, you have to start postmaster with the argument -i to listen to TCP connections. Took me a while to figure out. My postgresql 7.4 didn't want to let me in when using localhost as DSN hostname with PEAR...