cakephp1.3
版本开始支持事务操作:
例子
function delGranary($deletenode,$children)
{
$db =& ConnectionManager::getDataSource($this->useDbConfig);
#start the transaction
$db->begin($this);
try{
if($this->delete($deletenode))
{
if($this->GranaryMonitorConfig->query("delete from granary_monitor_configs where Granary_id=69"))
return $db->commit($this);
}
else throw new Exception('Model did not delete');
}
catch (Exception $e) {
$db->rollback();
}
}
参考例子
http://www.lampdeveloper.co.uk/mysql/using-mysql-transactions-in-cakephp.html