Re: DataObject and transactions
| From: | Alan Knowles | Date: | Sat, 16 Aug 2003 03:49:19 +0000 |
| Subject: | Re: DataObject and transactions | ||
| References: | 1 | Groups: | php.pear.general php.pear.general |
| Request: | Send a blank email to pear-general+get-7232@lists.php.net to get a copy of this message | ||
try yet another undocumented feature.. :)
$db = $dataObject->getDatabaseConnection();
$db->autoCommit(false);
if (!$dataObject->update()) {
$db->rollback();
if ($db->commit() !== DB_OK) {
....
}
Regards
Alan
Markus Wolff wrote:
Hi there, maybe some of you have encountered similar problems and can give me some hints: I need to make several insert/select/update statements using different DataObject-derived classes that all have to be part of one transaction that is automatically rolled back if any of the queries fail for some reason. I´ve found some old postings in this ML from last year, where Andrew Djachenko has tried to do it like this: $do1 = new DO_Type1; $do1->query('begin work'); ... loop ... $do1->insert(); ... end loop ... $do2 = new DO_Type2; $do2->insert(); $do1->query('rollback'); The rollback didn´t work for Andrew back then. Maybe this has changed in the time being? Now, DataObject uses DB. To use DB with transactions, you have to turn off autoCommit and issue a manual commit() after your last query. Is there a way to get DataObject to do the same? Is there anyone here who successfully got DO to work with transactions and still lives to talk about it? ;-) Another question: How can I find out if the transaction went through okay, or if it was rolled back because of some failure? And can I still query the reason for that failure? Thanks, Markus