diff --git a/src/Db/Query/Query.php b/src/Db/Query/Query.php index 714dbe900b42df5f1f0cadaf273b2e7340e899fd..3a80d774649ee885dc8b41a30c15aecb9dafb77c 100644 --- a/src/Db/Query/Query.php +++ b/src/Db/Query/Query.php @@ -184,6 +184,11 @@ abstract class Query implements IQuery */ public function getDb(): IDb { + if (!$this->isInitDb) + { + $this->db = Db::getInstance($this->poolName, $this->queryType); + } + return $this->db; } @@ -886,15 +891,7 @@ abstract class Query implements IQuery { 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 @@ abstract class Query implements IQuery */ 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(); } /**