This commit is contained in:
as2252258@163.com
2021-09-14 01:27:50 +08:00
parent fde7fd4994
commit a934bded3c
+13 -2
View File
@@ -178,8 +178,8 @@ class PDO implements StopHeartbeatCheck
/** /**
* @param string $sql * @param string $sql
* @param array $params * @param array $params
* @return array * @return bool|array|null
* @throws Exception * @throws \Exception
*/ */
public function fetchColumn(string $sql, array $params = []): bool|null|array public function fetchColumn(string $sql, array $params = []): bool|null|array
{ {
@@ -216,10 +216,21 @@ class PDO implements StopHeartbeatCheck
private function queryPrev(string $sql, array $params = []): PDOStatement private function queryPrev(string $sql, array $params = []): PDOStatement
{ {
$this->_last = time(); $this->_last = time();
try {
if (($statement = $this->_pdo()->query($sql)) === false) { if (($statement = $this->_pdo()->query($sql)) === false) {
throw new Exception($this->_pdo()->errorInfo()[1]); throw new Exception($this->_pdo()->errorInfo()[1]);
} }
return $this->bindValue($statement, $params); return $this->bindValue($statement, $params);
} catch (\Throwable $throwable) {
if (str_contains($throwable->getMessage(), 'MySQL server has gone away')) {
$this->pdo = null;
return $this->queryPrev($sql, $params);
}
throw new Exception($throwable->getMessage());
}
} }