PEAR is archived and read-only

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

Home » Database » DB » Bug #5982

No connection with PostgreSQL via sockets and non default port

Details

Submitted2005-11-16 11:42 UTC
Fromr dot m dot guerrero at usit dot uio dot no
Assignedlsmith
StatusClosed
PackageDB
PHP Version4.3.11
OSLinux RHEL WS 3
Roadmaps(Not assigned)

Comments

[2005-11-16 11:42 UTC] r dot m dot guerrero at usit dot uio dot no

Description:
------------
System:

- PostgreSQL 8.0.4
(socket in f.ex:/tmp/sockets/, port= 5433)
- PHP 4.3.11
- Apache 1.3.33
- pear DB 1.7.6

Using postgreSQL with a non standard port (f.ex.: 5433) would create the Unix domain socket /tmp/sockets/.s.PGSQL.5433. With the actual format of DSN, we can not define a non standard socket location with a non standad port.

We can define this:
pgsql://postgres@unix(/tmp/sockets/)/test

but this will try to connect to tmp/sockets/.s.PGSQL.5432 (default port) and it does not work if we are using another port.

"...(/tmp/sockets/:5433)" does not work, this tries to use /tmp/pg_sockets/bbking01:5433/.s.PGSQL.5432

I have patched DB.php (see patch) so it will be possible to define a socket directory and a port in DSN with the format:

phptype://user:passwd@unix(/path/to/socket:port)/database

Test script:
---------------
--- DB.php 2005-11-16 12:25:59.000000000 +0100
+++ DB_patched.php 2005-11-16 12:25:07.000000000 +0100
@@ -816,8 +816,13 @@ class DB
$parsed['hostspec'] = $proto_opts;
}
} elseif ($parsed['protocol'] == 'unix') {
- $parsed['socket'] = $proto_opts;
- }
+ if (strpos($proto_opts, ':') !== false) {
+ list($parsed['socket'],
+ $parsed['port']) = explode(':', $proto_opts);
+ } else {
+ $parsed['socket'] = $proto_opts;
+ }
+ }

// Get dabase if any
// $dsn => database