Connection类的transaction方法支持返回值

This commit is contained in:
thinkphp
2016-04-23 18:31:27 +08:00
parent 0ed23d6186
commit 8cca5524a7

View File

@@ -426,18 +426,20 @@ abstract class Connection
* 执行数据库事务 * 执行数据库事务
* @access public * @access public
* @param callable $callback 数据操作方法回调 * @param callable $callback 数据操作方法回调
* @return void * @return mixed
*/ */
public function transaction($callback) public function transaction($callback)
{ {
$this->startTrans(); $this->startTrans();
try { try {
if (is_callable($callback)) { if (is_callable($callback)) {
call_user_func_array($callback, []); $result = call_user_func_array($callback, []);
} }
$this->commit(); $this->commit();
return $result;
} catch (\PDOException $e) { } catch (\PDOException $e) {
$this->rollback(); $this->rollback();
return false;
} }
} }