From a95f2af9edf12797b8ce171c1a18608eda638bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Tue, 15 Aug 2023 23:50:26 +0800 Subject: [PATCH] qqq --- Command.php | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/Command.php b/Command.php index 61a418b..6391674 100644 --- a/Command.php +++ b/Command.php @@ -80,7 +80,7 @@ class Command extends Component try { return $this->prepare()->fetchAll(PDO::FETCH_ASSOC); } catch (Throwable $throwable) { - if ($this->canReconnect($throwable->getMessage())) { + if (str_contains($throwable->getMessage(),'MySQL server has gone away')) { return $this->all(); } return $this->error($throwable); @@ -98,7 +98,7 @@ class Command extends Component try { return $this->prepare()->fetch(PDO::FETCH_ASSOC); } catch (Throwable $throwable) { - if ($this->canReconnect($throwable->getMessage())) { + if (str_contains($throwable->getMessage(),'MySQL server has gone away')) { return $this->one(); } return $this->error($throwable); @@ -116,7 +116,7 @@ class Command extends Component try { return $this->prepare()->fetchColumn(PDO::FETCH_ASSOC); } catch (Throwable $throwable) { - if ($this->canReconnect($throwable->getMessage())) { + if (str_contains($throwable->getMessage(),'MySQL server has gone away')) { return $this->fetchColumn(); } return $this->error($throwable); @@ -134,7 +134,7 @@ class Command extends Component try { return $this->prepare()->rowCount(); } catch (Throwable $throwable) { - if ($this->canReconnect($throwable->getMessage())) { + if (str_contains($throwable->getMessage(),'MySQL server has gone away')) { return $this->rowCount(); } return $this->error($throwable); @@ -189,7 +189,7 @@ class Command extends Component return $result == 0 ? true : (int)$result; } catch (Throwable $throwable) { - if ($this->canReconnect($throwable->getMessage())) { + if (str_contains($throwable->getMessage(),'MySQL server has gone away')) { return $this->_execute(); } return $this->error($throwable); @@ -200,26 +200,6 @@ class Command extends Component } } - - /** - * @param string $message - * @return bool - */ - protected function canReconnect(string $message): bool - { - $errors = [ - 'MySQL server has gone away', - 'Packets out of order. Expected 1 received 0.' - ]; - foreach ($errors as $error) { - if (str_contains($message, $error)) { - return true; - } - } - return false; - } - - /** * @param Throwable $throwable * @return bool