Bug #16569 Updated: pg_close($conn2) closes all connections?

From: Date: Fri, 12 Apr 2002 16:37:50 +0000
Subject: Bug #16569 Updated: pg_close($conn2) closes all connections?
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-4753@lists.php.net to get a copy of this message
ID: 16569 Updated by: rasmus@php.net Reported By: mike@deat.com -Status: Open +Status: Bogus Bug Type: PostgreSQL related Operating System: RedHat 7.0 PHP Version: 4.1.1 New Comment: This is not a bug. If you look at the resource ids returned from the pg_connect() calls you would see that the second call actually returns the same resource id as the first. That is, $conn1 = $conn2, so naturally closing $conn2 will also close $conn1. Basically PHP keeps track of open connections and if you try to open a second connection with the exact same credentials it will reuse the existing one. Previous Comments: ------------------------------------------------------------------------ [2002-04-12 12:30:09] mike@deat.com /* TWO CONNECTIONS TO SAME SERVER, SAME DATABASE */ $conn1=pg_Connect("host=172.15.15.1 user=me dbname=mydb"); $conn2=pg_Connect("host=172.15.15.1 user=me dbname=mydb"); /* QUERIES HERE OK ON EITHER CONNECTION */ $result=pg_exec($conn1, "select stuff from table"); $result=pg_exec($conn2, "select stuff from table"); /* CLOSE conn2, conn1 SHOULD STILL BE OPEN */ $conn2=pg_close($conn2); $result=pg_exec($conn1, "select stuff from table"); // ERROR! $conn1 seems to have been closed! // MAYBE YOU ASK WHY WE DO TWO CONNS TO SAME db? // NORMALLY, THEY ARE TWO DIFFERENT db's, MAIN and // BACKUP. IN A failover SITUATION, BACKUP DB IS // DOING BOTH JOBS, SO BOTH CONNS TO SAME MACHINE // OUR PROBLEM FIXED WITH CONDITIONAL CODE: EG: IF // MAIN AND BACKUP DBS ARE SAME, DON'T MAKE SECOND // CONNECTION, BUT .... THOUGHT YOU SHOULD KNOW // ABOUT THIS. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=16569&edit=1

« previous php.bugs (#4753) next »