PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB » Bug #339

DB::PGSQL doesn't recognize sockets for a pgsql connection

Details

Submitted2003-12-03 08:14 UTC
Fromt dot rietsch at nzz dot ch
Assignedchagenbu
StatusClosed
PackageDB
PHP VersionIrrelevant
OSall
Roadmaps(Not assigned)

Comments

[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

[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.

[2007-02-21 07:30 UTC] spam at me dot not

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...