From 9712cfcb50ffa67b70a78b10b51e9ee2c4a538f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 23 Feb 2021 18:12:17 +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/Base/BaseActiveRecord.php | 4 ++-- Database/Command.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Database/Base/BaseActiveRecord.php b/Database/Base/BaseActiveRecord.php index f2511b17..663800f9 100644 --- a/Database/Base/BaseActiveRecord.php +++ b/Database/Base/BaseActiveRecord.php @@ -411,11 +411,11 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess $trance = $dbConnection->beginTransaction(); try { $commandExec = $dbConnection->createCommand($sqlBuilder, $param); - if (($lastId = $commandExec->save(true, $this)) === false) { + if (!($lastId = (int)$commandExec->save(true, $this))) { throw new Exception('保存失败.' . $sqlBuilder); } $trance->commit(); - $this->setPrimary($lastId = (int)$lastId, $param); + $this->setPrimary($lastId, $param); $this->event->dispatch(self::AFTER_SAVE, [$attributes, $param]); } catch (\Throwable $exception) { diff --git a/Database/Command.php b/Database/Command.php index 564a749b..b3ac6818 100644 --- a/Database/Command.php +++ b/Database/Command.php @@ -255,7 +255,7 @@ class Command extends Component if ($result == 0 && $hasAutoIncrement->hasAutoIncrement()) { return $this->addError($connection->errorInfo()[2], 'mysql'); } - return $result; + return $result == 0 ? true : $result; }