代码大概逻辑如下: 
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

记 PDO报 There is already an active transaction 报错

最后把代码逻辑调整,解决了这个问题 

try{

     Db::beginTransaction();

    $update; //更新操作

    $add; //新增操作 

    if($update===false ||  !$add ){
       throw new \Exception('dddd');
    } 
  Db::commit();
}catch (Execption $e){
  Db::rollback();
}
 

 

相关文章:

  • 2021-11-21
  • 2022-12-23
  • 2021-09-18
  • 2022-01-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-14
  • 2022-12-23
  • 2021-10-31
  • 2021-12-22
相关资源
相似解决方案