php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #18451 php4-pgsql should have a way to create a new database connection
Submitted: 2002-07-20 22:00 UTC Modified: 2011-01-01 00:55 UTC
From: shane at cm dot nu Assigned:
Status: Not a bug Package: PostgreSQL related
PHP Version: 4.2.1 OS: Linux
Private report: No CVE-ID: None
 [2002-07-20 22:00 UTC] shane at cm dot nu
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [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
Fixed by passing PGSQL_CONNECT_FORCE_NEW as 2nd param to pg_connect(). (no idea in what version this was added)
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Aug 19 03:01:27 2019 UTC