From 80d1c6f2dee658ed9ca28bab51a03db690f60558 Mon Sep 17 00:00:00 2001 From: zxin <14545600+NHZEX@users.noreply.github.com> Date: Wed, 7 Jun 2023 13:22:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=A4=E6=96=AD=E4=BA=8B?= =?UTF-8?q?=E5=8A=A1=E6=97=B6Db=E5=AE=9E=E4=BE=8B=E9=94=99=E8=AF=AF=20(#53?= =?UTF-8?q?2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Db/Query/Query.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Db/Query/Query.php b/src/Db/Query/Query.php index 714dbe900b..3a80d77464 100644 --- a/src/Db/Query/Query.php +++ b/src/Db/Query/Query.php @@ -184,6 +184,11 @@ public function setOption($option): self */ public function getDb(): IDb { + if (!$this->isInitDb) + { + $this->db = Db::getInstance($this->poolName, $this->queryType); + } + return $this->db; } @@ -886,15 +891,7 @@ protected function executeEx(string $sql, string $resultClass) { try { - $db = &$this->db; - if (!$this->isInitDb) - { - $db = Db::getInstance($this->poolName, $this->queryType); - } - if (!$db) - { - return new $resultClass(false); - } + $db = $this->getDb(); $stmt = $db->prepare($sql); $binds = $this->binds; $this->binds = []; @@ -971,7 +968,12 @@ public function setFieldDec(string $fieldName, float $decValue = 1): self */ protected function isInTransaction(): bool { - return QueryType::WRITE === $this->queryType && Db::getInstance($this->poolName)->inTransaction(); + if (QueryType::WRITE !== $this->queryType) + { + return false; + } + + return $this->getDb()->inTransaction(); } /**