I don't want to bug, but is there no one on the list that knows the answer to this question? I haven't received any responses.
--Seth
From: Atkins, Seth (RICH1:5278)
Sent: Wednesday, April 29, 2009 6:23 PM
To: fw-mvc@lists.zend.com
Subject: DB transactions and Zend_Db_Table
I mostly use Zend_Db_Table to query and update rows in the database since it tends to simplify things due to being able to define relationships, primary keys, etc. Occasionally, I end up having to make calls to the DB adapter object for things like quoteInto, fetchPairs, etc.
Now if I want to lump multiple table updates into a transaction, the ZF docs show how to do this using the Adapter class. For example:
$db->beginTransaction();
try {
// Attempt to execute one or more queries:
$db->query(...);
$db->query(...);
$db->query(...);
// If all succeed, commit the transaction and all changes
// are committed at once.
$db->commit();
} catch (exception $e) {
$tableA->getAdapter()->rollback();
..........
}
Should I take that to mean that this is the only way to implement transactions? I know I can indirectly access adapter methods with $myTable->getAdapter()->method() calls, but will the following work?
$tableA->getAdapter()->beginTransaction();
try {
// Attempt to execute one or more queries:
$rowA = $tableA->fetch(...);
$rowB = $tableB->fetch(...);
//do stuff to each row object;
$rowA->save();
$rowB->save();
// If all succeed, commit the transaction and all changes
// are committed at once.
$tableA->getAdapter()->commit();
} catch (exception $e) {
$tableA->getAdapter()->rollback();
..........
}
Seth Atkins
没有评论:
发表评论