From 6cfae7360be86d0f96421a538b68392753554e44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 27 Apr 2021 16:36:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Database/Command.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Database/Command.php b/Database/Command.php index d8479a63..9e7a6ec4 100644 --- a/Database/Command.php +++ b/Database/Command.php @@ -194,18 +194,14 @@ class Command extends Component */ private function insert_or_change($isInsert, $hasAutoIncrement): bool|string { - if (!($connection = $this->initPDOStatement())) { - return false; - } - if (($result = $this->prepare->execute($this->params)) === false) { - return $this->addError($connection->errorInfo()[2], 'mysql'); + if (!($result = $this->initPDOStatement())) { + return $result; } if ($isInsert === false) { return true; } - $result = $connection->lastInsertId(); if ($result == 0 && $hasAutoIncrement->isAutoIncrement()) { - return $this->addError($connection->errorInfo()[2], 'mysql'); + return $this->addError('The system is busy, please try again later.', 'mysql'); } return $result == 0 ? true : $result; } @@ -215,7 +211,7 @@ class Command extends Component * 重新构建 * @throws */ - private function initPDOStatement(): PDO|bool|null + private function initPDOStatement(): bool|int { if (empty($this->sql)) { return $this->addError('no sql.', 'mysql'); @@ -227,7 +223,12 @@ class Command extends Component if (!($this->prepare instanceof PDOStatement)) { return $this->addError($this->sql . ':' . $this->getError(), 'mysql'); } - return $connect; + $result = $this->prepare->execute($this->params); + $this->prepare->closeCursor(); + if ($result === false) { + return $this->addError($connect->errorInfo()[2], 'mysql'); + } + return (int)$connect->lastInsertId(); } /**