Yii AR事务操作

Yii Ar事务操作,示例代码如下:

$model=Post::model();  
$transaction=$model->dbConnection->beginTransaction();  
try  
{  
    // 查找和保存是可能由另一个请求干预的两个步骤  
    // 这样我们使用一个事务以确保其一致性和完整性  
    $post=$model->findByPk(10);  
    $post->title='new post title';  
    $post->save();  
    $transaction->commit();  
}  
catch(Exception $e)  
{  
    $transaction->rollBack();  
}

  

posted @ 2014-11-12 14:18  sungx2009  阅读(249)  评论(0编辑  收藏  举报