php there is no active transaction,PDO:There is no active transaction

报错

sentry后台看到这个错误There is no active transaction,这个问题出现在一个update方法里,大致是

function update() {

$this->db->beginTrans();

try {

dosomething();

$this->db->commitTrans();

} catch (\Exception $ex) {

this->db->rollBackTrans();

throw $ex;

}

}

dosomething()方法我也仔细检查过来,没有开启事务,结束事务的地方,报错位置就在$this->db->commitTrans();这一行,有点奇怪为什么没有事务?

db类

我猜测是db类的问题(没开启事务),这个类是我拿workman mysql helper改的(加了一个主从读取而已),源码在这里,我开启事务部分是

public function beginTrans()

{

$this->Trans = true;

try {

return $this->pdo->beginTransaction();

} catch (PDOException $e) {

// 服务端断开时重连一次

if ($e->errorInfo[1] == 2006 || $e->errorInfo[1] == 2013) {

$this->closeConnection();

$this->pdoRW = $this->getConnectionInstance($this->configs['rw']);

$this->pdo = $this->pdoRW;

return $this->pdo->beginTransaction();

} else {

throw $e;

}

}

}

不过,也是会开启事务,很奇怪问题发生原因(这个问题有时候会发生)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值