Re: PostgreSQL and transactions.
| From: | Paul Cooper | Date: | Mon, 08 Oct 2001 19:01:21 +0000 |
| Subject: | Re: PostgreSQL and transactions. | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-13108@lists.php.net to get a copy of this message | ||
On Mon, Oct 08, 2001 at 12:13:10PM +0100, Morten Bruun wrote:
> Hi there!
>
> I was thinking about using PostgreSQL because I need the transaction
> management features, but I've come across a problem:
>
> $connection1 = pg_pconnect('dbname=mydb');
> $connection2 = pg_pconnect('dbname=mydb');
>
> pg_exec($connection1, "begin");
> pg_Exec($connection1, "insert into mytable values ('firstvalue')");
> pg_Exec($connection2, "insert into mytable values ('secondvalue')");
> pg_Exec($connection1, "rollback");
Why do you need two connections?
> This piece of code didn't do what I expected it to do. I does not insert
> 'secondvalue' into the table mytable. I looked around in the manual
> (http://www.php.net/manual/en/) and found out that two identical calls to
> pg_connect() returns the same connection.
Above you have used pg_pconnect() which is a persistent connection, so it
should return the same connection within the script. Theoretically if you
use pg_connect it should do what you want - but you don't seem to need 2
connections (unless i'm missing something).
Paul
> Is there any way of avoiding this? And does that mean that different
> request to a php page gets the same connection to the database?
>
> Thanks in advance!
>
> /Morten
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
> For additional commands, e-mail: php-db-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
--
-----------------------------------------------------------------
Paul Cooper | Tel: 0121 331 7858
Senior Programmer and Database Engineer | Fax: 0121 331 7859
UCEcom | mailto:pgc@ucecom.com
University of Central England | http://www.ucecom.com
Birmingham, B4 7DX |
-----------------------------------------------------------------