官方源代码
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;
}
}
}