mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
改进事务的断线重连
This commit is contained in:
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user