mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
改进事务的断线重连
This commit is contained in:
@@ -382,12 +382,12 @@ abstract class Connection
|
|||||||
// 返回结果集
|
// 返回结果集
|
||||||
return $this->getResult($pdo, $procedure);
|
return $this->getResult($pdo, $procedure);
|
||||||
} catch (\PDOException $e) {
|
} catch (\PDOException $e) {
|
||||||
if ($this->config['break_reconnect'] && $this->isBreak($e)) {
|
if ($this->isBreak($e)) {
|
||||||
return $this->close()->query($sql, $bind, $master, $pdo);
|
return $this->close()->query($sql, $bind, $master, $pdo);
|
||||||
}
|
}
|
||||||
throw new PDOException($e, $this->config, $this->getLastsql());
|
throw new PDOException($e, $this->config, $this->getLastsql());
|
||||||
} catch (\ErrorException $e) {
|
} catch (\ErrorException $e) {
|
||||||
if ($this->config['break_reconnect'] && $this->isBreak($e)) {
|
if ($this->isBreak($e)) {
|
||||||
return $this->close()->query($sql, $bind, $master, $pdo);
|
return $this->close()->query($sql, $bind, $master, $pdo);
|
||||||
}
|
}
|
||||||
throw $e;
|
throw $e;
|
||||||
@@ -445,12 +445,12 @@ abstract class Connection
|
|||||||
$this->numRows = $this->PDOStatement->rowCount();
|
$this->numRows = $this->PDOStatement->rowCount();
|
||||||
return $this->numRows;
|
return $this->numRows;
|
||||||
} catch (\PDOException $e) {
|
} catch (\PDOException $e) {
|
||||||
if ($this->config['break_reconnect'] && $this->isBreak($e)) {
|
if ($this->isBreak($e)) {
|
||||||
return $this->close()->execute($sql, $bind);
|
return $this->close()->execute($sql, $bind);
|
||||||
}
|
}
|
||||||
throw new PDOException($e, $this->config, $this->getLastsql());
|
throw new PDOException($e, $this->config, $this->getLastsql());
|
||||||
} catch (\ErrorException $e) {
|
} catch (\ErrorException $e) {
|
||||||
if ($this->config['break_reconnect'] && $this->isBreak($e)) {
|
if ($this->isBreak($e)) {
|
||||||
return $this->close()->execute($sql, $bind);
|
return $this->close()->execute($sql, $bind);
|
||||||
}
|
}
|
||||||
throw $e;
|
throw $e;
|
||||||
@@ -628,13 +628,25 @@ abstract class Connection
|
|||||||
}
|
}
|
||||||
|
|
||||||
++$this->transTimes;
|
++$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) {
|
} catch (\PDOException $e) {
|
||||||
$this->linkID->beginTransaction();
|
if ($this->isBreak($e)) {
|
||||||
} elseif ($this->transTimes > 1 && $this->supportSavepoint()) {
|
return $this->close()->startTrans();
|
||||||
$this->linkID->exec(
|
}
|
||||||
$this->parseSavepoint('trans' . $this->transTimes)
|
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)
|
protected function isBreak($e)
|
||||||
{
|
{
|
||||||
|
if (!$this->config['break_reconnect']) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$info = [
|
$info = [
|
||||||
'server has gone away',
|
'server has gone away',
|
||||||
'no connection to the server',
|
'no connection to the server',
|
||||||
|
|||||||
Reference in New Issue
Block a user