|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2011-01-01 00:55 UTC] jani@php.net
-Status: Open
+Status: Bogus
-Package: Feature/Change Request
+Package: PostgreSQL related
[2011-01-01 00:55 UTC] jani@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 20:00:01 2025 UTC |
Hi, When calling pg_connect, the function reuses existing database connections if they are available. For example. $dbh1 = pg_connect(); $dbh2 = pg_connect(); $dbh1 == $dbh2 at this point. However, as there is no way to tell PHP to create a new connection, the reuse can potentially corrupt a transaction. For example: $dbh1 = pg_conect(); pg_query("begin", $dbh1); pg_query("insert into mytable values(...)"), $dbh1); $dbh2 = pg_connect(); ($dbh2 == $dbh1) not good. pg_query("something stupid that causes an error", $dbh2); pg_query("commit", $dbh1); fails The same problem applies to persistant connections though it looks like php does a rollback when a connection terminates which is good. I think the only real fix for this is pg_connect and pg_pconnect should always return a different handle on a call even when not in a transaction. The only time pg_pconnect should return a previously used handle is when pg_pclose has been called. You garantee transaction safety that way and if the programmer wants to reuse database handles, let him declare a global handle. Best regards, Shane