From 0a6fbed5d0626fd2170f9332af29a68e8fa0e3a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Fri, 7 Apr 2023 21:41:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Command.php | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/Command.php b/Command.php index e0e8bdc..d6a59bb 100644 --- a/Command.php +++ b/Command.php @@ -67,13 +67,11 @@ class Command extends Component public function all(): null|bool|array { try { - $pdo = $this->connection->getConnection(); - if (($prepare = $pdo->query($this->sql)) === false) { - throw new Exception($pdo->errorInfo()[1]); - } - foreach ($this->params as $key => $param) { - $prepare->bindParam($key, $param); + $client = $this->connection->getConnection(); + if (($prepare = $client->prepare($this->sql)) === false) { + throw new Exception($client->errorInfo()[1]); } + $prepare->execute($this->params); return $prepare->fetchAll(PDO::FETCH_ASSOC); } catch (\Throwable $throwable) { if (str_contains($throwable->getMessage(), 'MySQL server has gone away')) { @@ -81,7 +79,7 @@ class Command extends Component } return $this->error($throwable); } finally { - $this->connection->release($pdo ?? null); + $this->connection->release($client ?? null); } } @@ -116,12 +114,10 @@ class Command extends Component { try { $client = $this->connection->getConnection(); - if (($prepare = $client->query($this->sql)) === false) { + if (($prepare = $client->prepare($this->sql)) === false) { throw new Exception($client->errorInfo()[1]); } - foreach ($this->params as $key => $param) { - $prepare->bindParam($key, $param, PDO::PARAM_STR | PDO::PARAM_INT); - } + $prepare->execute($this->params); return $prepare->fetchColumn(PDO::FETCH_ASSOC); } catch (\Throwable $throwable) { if (str_contains($throwable->getMessage(), 'MySQL server has gone away')) { @@ -141,12 +137,10 @@ class Command extends Component { try { $client = $this->connection->getConnection(); - if (($prepare = $client->query($this->sql)) === false) { + if (($prepare = $client->prepare($this->sql)) === false) { throw new Exception($client->errorInfo()[1]); } - foreach ($this->params as $key => $param) { - $prepare->bindParam($key, $param, PDO::PARAM_STR | PDO::PARAM_INT); - } + $prepare->execute($this->params); return $prepare->rowCount(); } catch (\Throwable $throwable) { if (str_contains($throwable->getMessage(), 'MySQL server has gone away')) {