diff --git a/library/think/db/Driver.php b/library/think/db/Driver.php index 2e079072..1045c53f 100644 --- a/library/think/db/Driver.php +++ b/library/think/db/Driver.php @@ -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