Db类增加 transaction 方法用于执行某组数据事务操作

This commit is contained in:
thinkphp
2016-04-10 14:30:26 +08:00
parent 9ac9d43a46
commit 42073f04f9

View File

@@ -366,6 +366,24 @@ abstract class Driver
return $result;
}
/**
* 执行数据库事务
* @access public
* @param callable $callback 数据操作方法回调
* @return void
*/
public function transaction($callback){
$this->startTrans();
try {
if (is_callable($callback)) {
call_user_func_array($callback, [$sql, $runtime, $explain]);
}
$this->commit();
}catch (\PDOException $e) {
$this->rollback()
}
}
/**
* 启动事务
* @access public