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 array $params
* @return array
* @throws Exception
* @return bool|array|null
* @throws \Exception
*/
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
{
$this->_last = time();
try {
if (($statement = $this->_pdo()->query($sql)) === false) {
throw new Exception($this->_pdo()->errorInfo()[1]);
}
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());
}
}