ID: 818
Updated by: jimw
Old-Status: Analyzed
Status: Closed
Bug Type: Feature/Change Request
Assigned To: zeev

this was a duplicate of 729.

Previous Comments:

[1998-10-05 10:36:40] [EMAIL PROTECTED]
pg_Connect() doesn't always return a unique connection identifier. This is a problem 
for code that uses nested
connections, or code that "hides" connections by using 

One work-around is to not explicitly call pg_Close() from the nested connection. The 
other is to do away with this feature - because it smells a lot like pg_pConnect(). 

Here's a small piece of code:


$HOST = "localhost";
$PORT = "5432";
$DATABASE = "template1";

function Nested() {
        global $HOST, $PORT, $DATABASE;
        $conn = pg_Connect($HOST, $PORT, "", "", $DATABASE);
        if ($conn) {
                echo "Nested id: $connn";

function SomeFunc() {
        global $HOST, $PORT, $DATABASE;
        $conn = pg_Connect($HOST, $PORT, "", "", $DATABASE);
        if ($conn) {
                echo "First id: $connn";



Running this code yields:

First id: 1
Nested id: 1
<b>Warning</b>:  1 is not a PostgreSQL link index in <b>foo.php3</b> on line 

The expected output is:

First id: 1
Nested id: 2

The cause is the lookup performed inside pg_Connect(). Whenever a connection is 
established, it's stored in a hash table. Then, when a new connection is requested, 
the connection parameters are looked up in the hash table, and if a match is found, an 
existing connection id is returned. You can see this behaviour by changing one of the 
above pg_Connect() lines to:

$conn = pg_Connect("", $PORT, "", "", $DATABASE);

This will cause the lookup to fail because localhost looks different from in 
the lookup.

I have a feeling this may be something leftover from before pg_pConnect()... 

-Brian Schaffner-


ATTENTION! Do NOT reply to this email!
To reply, use the web interface found at

PHP Development Mailing List <>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to