php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16569 pg_close($conn2) closes all connections?
Submitted: 2002-04-12 12:30 UTC Modified: 2002-04-12 12:37 UTC
From: mike at deat dot com Assigned:
Status: Not a bug Package: PostgreSQL related
PHP Version: 4.1.1 OS: RedHat 7.0
Private report: No CVE-ID: None
 [2002-04-12 12:30 UTC] mike at deat dot 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.








Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-12 12:37 UTC] rasmus@php.net
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.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Aug 22 08:01:27 2019 UTC