欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 运维知识 > 数据库 >内容正文

数据库

mysql 开启断线重连_[BUG反馈]MYSQL长连接中(SWOOLE) 使用事务提交开启断线重连接抛出异常...

发布时间:2025/4/5 数据库 59 豆豆
生活随笔 收集整理的这篇文章主要介绍了 mysql 开启断线重连_[BUG反馈]MYSQL长连接中(SWOOLE) 使用事务提交开启断线重连接抛出异常... 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

官方源代码

vendor/topthink/think-orm/src/db/PDOConnection.php :1369行public function startTrans(): void

{

$this->initConnect(true);

++$this->transTimes;

try {

if (1 == $this->transTimes) {

$this->linkID->beginTransaction();

} elseif ($this->transTimes > 1 && $this->supportSavepoint()) {

$this->linkID->exec(

$this->parseSavepoint('trans' . $this->transTimes)

);

}

$this->reConnectTimes = 0;

} catch (\Exception $e) {

if ($this->reConnectTimes isBreak($e)) {

--$this->transTimes;

++$this->reConnectTimes;

$this->close()->startTrans();

}

throw $e;

}

}修复建议: 在"throw $e;"上面加个else或 使用return阻止抛出异常public function startTrans(): void

{

$this->initConnect(true);

++$this->transTimes;

try {

if (1 == $this->transTimes) {

$this->linkID->beginTransaction();

} elseif ($this->transTimes > 1 && $this->supportSavepoint()) {

$this->linkID->exec(

$this->parseSavepoint('trans' . $this->transTimes)

);

}

$this->reConnectTimes = 0;

} catch (\Exception $e) {

if ($this->reConnectTimes isBreak($e)) {

--$this->transTimes;

++$this->reConnectTimes;

$this->close()->startTrans();

}else{

throw $e;

}

}

}

总结

以上是生活随笔为你收集整理的mysql 开启断线重连_[BUG反馈]MYSQL长连接中(SWOOLE) 使用事务提交开启断线重连接抛出异常...的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。