|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2001-02-10 12:31 UTC] jimw@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 06:00:01 2025 UTC |
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 objects. 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: $conn\n"; pg_Close($conn); } } function SomeFunc() { global $HOST, $PORT, $DATABASE; $conn = pg_Connect($HOST, $PORT, "", "", $DATABASE); if ($conn) { echo "First id: $conn\n"; Nested(); pg_Close($conn); } } SomeFunc(); ?> Running this code yields: First id: 1 Nested id: 1 <br> <b>Warning</b>: 1 is not a PostgreSQL link index in <b>foo.php3</b> on line <b>23</b><br> 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("127.0.0.1", $PORT, "", "", $DATABASE); This will cause the lookup to fail because localhost looks different from 127.0.0.1 in the lookup. I have a feeling this may be something leftover from before pg_pConnect()... -Brian Schaffner-