歴史的な理由から、すべてのモデルは Zend_Db_Table から拡張されています。そして今、トランザクションを使用する必要があります。どうやって?
私はいくつかのグーグルを行いましたが、次の方法が役立つと言う人もいます:
1: $tableA->getAdapter()->beginTransaction(); 2: $tableA->getAdapter()->getDriver()->getConnection()->beginTransaction();
より良い解決策はありますか?
歴史的な理由から、すべてのモデルは Zend_Db_Table から拡張されています。そして今、トランザクションを使用する必要があります。どうやって?
私はいくつかのグーグルを行いましたが、次の方法が役立つと言う人もいます:
1: $tableA->getAdapter()->beginTransaction(); 2: $tableA->getAdapter()->getDriver()->getConnection()->beginTransaction();
より良い解決策はありますか?
zend_db_tableに次のコードを追加することで問題を解決しました:/***サポートトランザクション*/
public function beginTransaction() {
$this->getAdapter()->beginTransaction();
}
public function commit() {
$this->getAdapter()->commit();
}
public function rollback() {
$this->getAdapter()->rollback();
}
次のようにzend_db_tableから拡張するモデルでトランザクションを使用できるようにします。
public function test(){
$this->beginTransaction();
try {
$this->addCourseItem('1', '1', '1', '1', '1');
$this->fetchRow("none-exist-field = 1");
//the following code will not execute
echo "okay";
$this->commit();
} catch (exception $e) {
$this->rollback();
echo "error message:".$e->getMessage();
}
}