From c14988ee848a020a8b4173cb413656e1c30844eb Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 19 May 2017 11:27:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E4=BA=8B=E5=8A=A1=E7=9A=84?= =?UTF-8?q?=E6=96=AD=E7=BA=BF=E9=87=8D=E8=BF=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Connection.php | 36 ++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index bb2b02be..fa773e51 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -382,12 +382,12 @@ abstract class Connection // 返回结果集 return $this->getResult($pdo, $procedure); } catch (\PDOException $e) { - if ($this->config['break_reconnect'] && $this->isBreak($e)) { + if ($this->isBreak($e)) { return $this->close()->query($sql, $bind, $master, $pdo); } throw new PDOException($e, $this->config, $this->getLastsql()); } catch (\ErrorException $e) { - if ($this->config['break_reconnect'] && $this->isBreak($e)) { + if ($this->isBreak($e)) { return $this->close()->query($sql, $bind, $master, $pdo); } throw $e; @@ -445,12 +445,12 @@ abstract class Connection $this->numRows = $this->PDOStatement->rowCount(); return $this->numRows; } catch (\PDOException $e) { - if ($this->config['break_reconnect'] && $this->isBreak($e)) { + if ($this->isBreak($e)) { return $this->close()->execute($sql, $bind); } throw new PDOException($e, $this->config, $this->getLastsql()); } catch (\ErrorException $e) { - if ($this->config['break_reconnect'] && $this->isBreak($e)) { + if ($this->isBreak($e)) { return $this->close()->execute($sql, $bind); } throw $e; @@ -628,13 +628,25 @@ abstract class Connection } ++$this->transTimes; + try { + if (1 == $this->transTimes) { + $this->linkID->beginTransaction(); + } elseif ($this->transTimes > 1 && $this->supportSavepoint()) { + $this->linkID->exec( + $this->parseSavepoint('trans' . $this->transTimes) + ); + } - if (1 == $this->transTimes) { - $this->linkID->beginTransaction(); - } elseif ($this->transTimes > 1 && $this->supportSavepoint()) { - $this->linkID->exec( - $this->parseSavepoint('trans' . $this->transTimes) - ); + } catch (\PDOException $e) { + if ($this->isBreak($e)) { + return $this->close()->startTrans(); + } + throw $e; + } catch (\ErrorException $e) { + if ($this->isBreak($e)) { + return $this->close()->startTrans(); + } + throw $e; } } @@ -775,6 +787,10 @@ abstract class Connection */ protected function isBreak($e) { + if (!$this->config['break_reconnect']) { + return false; + } + $info = [ 'server has gone away', 'no connection to the server',