From 865e126fcc1f48a0eecd25512f104f4a4b677bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Sun, 6 Sep 2020 04:44:13 +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 | 50 +++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/Database/Command.php b/Database/Command.php index 77ce3a1d..1bd77f7d 100644 --- a/Database/Command.php +++ b/Database/Command.php @@ -41,24 +41,6 @@ class Command extends Component /** @var PDOStatement */ private $prepare; - /** - * 重新构建 - * @throws - */ - private function initPDOStatement() - { - if (empty($this->sql)) { - return null; - } - if (!(($connect = $this->db->getConnect($this->sql)) instanceof PDO)) { - return null; - } - $this->prepare = $connect->prepare($this->sql); - if (!($this->prepare instanceof PDOStatement)) { - return $this->addError($this->sql . ':' . $this->getError()); - } - return $this->prepare; - } /** * @return bool|PDOStatement @@ -255,23 +237,43 @@ class Command extends Component */ private function insert_or_change($isInsert, $hasAutoIncrement) { - if (!$this->initPDOStatement()) { + if (!($connection = $this->initPDOStatement())) { return false; } - $this->bind($this->prepare); - if (($result = $this->prepare->execute()) === false) { - return $this->addErrorLog(); + if (($result = $this->prepare->execute($this->prepare)) === false) { + return $this->addError($connection->errorInfo()[2]); } if (!$isInsert) { return true; } - $result = $this->connection->lastInsertId(); + $result = $connection->lastInsertId(); if ($result == 0 && $hasAutoIncrement) { - return $this->addErrorLog(); + return $this->addError($connection->errorInfo()[2]); } return $result; } + + + /** + * 重新构建 + * @throws + */ + private function initPDOStatement() + { + if (empty($this->sql)) { + return null; + } + if (!(($connect = $this->db->getConnect($this->sql)) instanceof PDO)) { + return null; + } + $this->prepare = $connect->prepare($this->sql); + if (!($this->prepare instanceof PDOStatement)) { + return $this->addError($this->sql . ':' . $this->getError()); + } + return $connect; + } + /** * @param $modelName * @return $this