For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > May 2007 > Transactions in MD2









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Transactions in MD2
Florian Schmitz

2007-05-18, 8:00 am

Hi.

I intend to switch from ADOdb to MDB2, primarily because the XML
features appear to be better thought out in MDB2. Now before doing
this rather tedious work, I'd like to clarify any uncertainties.
Currently, I don't see how transactions would work for me. In ADOdb
it's basically like this:

$conn->StartTrans();
$conn->Execute($sql);
$conn->Execute($Sql2);
$conn->CompleteTrans();

So I start a transactions, execute any commands and at the end check
whether or not something failed and I have to do a rollback.

According to the manual, in MDB2 it works like this:

$mdb2->beginTransaction();
$mdb2->query($sql);
$mdb2->query($Sql2);
[...]
// determine if the commit or rollback
if ($error_condition) {
$res = $mdb2->rollback();
} else {
$res = $mdb2->commit();
}

Interestingly, the manual doesn't mention the most important point,
that is, how to determine $error_condition and thus decide whether or
not to rollback the changes. The only method I could think of is
checking every single query manually for an error, but I certainly
won't do this for obvious reasons (bloat, work, error prone, ...).

Can anyone enlighten me concerning this issue?

Regards,
Florian
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com