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

一时失言乱红尘 2023-01-17 10:53 255阅读 0赞

报错

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;

}

}

}

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

发表评论

表情:
评论列表 (有 0 条评论,255人围观)

还没有评论,来说两句吧...

相关阅读