pg.ddx.io pgsql-php@postgresql.org mailing list archive
help / color / mirror / Atom feedcommit and rollback
2+ messages / 2 participants
[nested] [flat]
* commit and rollback
@ 2005-09-10 07:48 WeiShang <thanks@verymuch.com>
2005-09-13 11:53 ` Re: commit and rollback John DeSoi <desoi@pgedit.com>
0 siblings, 1 reply; 2+ messages in thread
From: WeiShang @ 2005-09-10 07:48 UTC (permalink / raw)
To: pgsql-php
Hi,
I have a problem about commit and rollback using php. For the script below,
if "foo" is called and commit and if rollback statment also run. Will the
update statement under foo also rollback? or commit?
Thanks in advance!
----------------------------------------------------------------------------
-----------Script starts
function foo(var1,var2)
{
pg_query($db,"begin");
pg_query($db,"<update statement here>");
pg_query($db,"commit");
}
pg_query($db,"begin");
.....
foo(v1,v2);
$result1=pg_query($db,"<update statment here>");
if (pg_affected_rows($result)==0)
pg_query($db,"rollback");
else
pg_query($db,"commit");
----------------------------------------------------------------------------
-----------Script end
--
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: commit and rollback
2005-09-10 07:48 commit and rollback WeiShang <thanks@verymuch.com>
@ 2005-09-13 11:53 ` John DeSoi <desoi@pgedit.com>
0 siblings, 0 replies; 2+ messages in thread
From: John DeSoi @ 2005-09-13 11:53 UTC (permalink / raw)
To: WeiShang <thanks@verymuch.com>; +Cc: pgsql-php
On Sep 10, 2005, at 3:48 AM, WeiShang wrote:
> I have a problem about commit and rollback using php. For the
> script below,
> if "foo" is called and commit and if rollback statment also run.
> Will the
> update statement under foo also rollback? or commit?
It will commit, but it will also complete the transaction causing
everything after it to run outside the transaction. Probably not what
you would want to do.
If foo can be called both inside and outside of a transaction, you
should call pg_transaction_status (assuming PHP 5) and only begin/
commit in foo if there is no existing transaction. If you are not
using PHP 5, then setup some flag to know if you are in a transaction.
John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2005-09-13 11:53 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-09-10 07:48 commit and rollback WeiShang <thanks@verymuch.com>
2005-09-13 11:53 ` John DeSoi <desoi@pgedit.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox