pg.ddx.io pgsql-php@postgresql.org mailing list archive
help / color / mirror / Atom feedfirst transactions
2+ messages / 2 participants
[nested] [flat]
* first transactions
@ 2008-03-12 08:47 A B <gentosaker@gmail.com>
0 siblings, 1 reply; 2+ messages in thread
From: A B @ 2008-03-12 08:47 UTC (permalink / raw)
To: pgsql-php
Hello.
I think I need some help on making it clear on how to use transactions
in php in a "correct" way.
Lets consider this code/pseudocode
function dostuff()
{
$db = pg_pconnect...;
pg_query("begin work",$db);
$result = pg_query("select ***",$db);
$result = pg_query("insert ***",$db);
if previous query failed, then rollback and return false
else
{
$result = pg_query("update ***",$db);
$result = pg_query("select ***",$db);
$result = pg_query("insert ***",$db);
$result = pg_query("update ***",$db);
pg_query("commit,$db);
if everything was successfully committed
return true;
else
return false or some other kind of error status to tell what went wrong.
}
} //end function
So the question is: how do I write the pseudocode parts in php?
Any other general suggestions on how to make the function more "fool
proof" is appreciated. :-)
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: first transactions
@ 2008-03-12 16:29 Jeff MacDonald <jam@zoidtechnologies.com>
parent: A B <gentosaker@gmail.com>
0 siblings, 0 replies; 2+ messages in thread
From: Jeff MacDonald @ 2008-03-12 16:29 UTC (permalink / raw)
To: pgsql-php; +Cc: A B <gentosaker@gmail.com>
On Wednesday 12 March 2008 4:47:33 am A B wrote:
> Hello.
>
> I think I need some help on making it clear on how to use transactions
> in php in a "correct" way.
>
> Lets consider this code/pseudocode
>
[...snipped...]
> So the question is: how do I write the pseudocode parts in php?
> Any other general suggestions on how to make the function more "fool
> proof" is appreciated. :-)
I recommend use of PEAR::MDB2[1] or "PDO"[2].. typically what I do is run
the query, rollback if error, continue if not. if you want to be extra
thorough using MDB2, you can check to make sure the database supports
transactions, and after a "begin" you can make sure that the transaction has
been started. my understanding is that PDO has a *very* similar interface to
MDB2, except that PDO is written in C.
hope that helps some.. if you have more questions post again or email me
directly.
regards,
jeff
[1] http://pear.php.net/mdb2
[2] http://php.net/pdo
--
http://zoidtechnologies.com/
"websites that suck less"
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2008-03-12 16:29 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-03-12 08:47 first transactions A B <gentosaker@gmail.com>
2008-03-12 16:29 ` Jeff MacDonald <jam@zoidtechnologies.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