Yii Framework中trasaction事务的应用 [ 技术分享 ]
$model=Post::model();
$transaction=$model->dbConnection->beginTransaction();
try
{
// find and save are two steps which may be intervened by another request
// we therefore use a transaction to ensure consistency and integrity
$post=$model->findByPk(10);
$post->title='new post title';
$post->save();
$transaction->commit();
}
catch(Exception $e)
{
$transaction->rollBack();
}
共 7 条回复
╃巡洋艦㊣ 北京
注册时间:2010-11-21
最后登录:1小时前
在线时长:1681小时55分
最后登录:1小时前
在线时长:1681小时55分
- 粉丝1369
- 金钱77013
- 威望845
- 积分102273