记 PDO报 There is already an active transaction 报错
代码大概逻辑如下:
Db::beginTransaction();
$update //更新操作
$add //新增操作
if(! $add && $update===false){
Db::rollback();
}else{
Db::commit();
}
查看日志,在add时有一条数据异常,导致新增失败
后面就一直报 There is already an active transaction
查了很多资料,看到了别人一个异常解决
http://php.net/manual/zh/pdo.begintransaction.php
最后把代码逻辑调整,解决了这个问题
try{
Db::beginTransaction();
$update; //更新操作
$add; //新增操作
if($update===false || !$add ){
throw new \Exception('dddd');
}
Db::commit();
}catch (Execption $e){
Db::rollback();
}