From 55b99355d79263f7a2c2118cf51e90afc733392c Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 26 Jan 2017 13:55:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BB=E7=9A=84setBui?= =?UTF-8?q?lder=E6=96=B9=E6=B3=95=20=E9=81=BF=E5=85=8D=E5=9B=A0=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E8=BF=9E=E6=8E=A5=E5=99=A8=E7=B1=BB=E5=90=8E?= =?UTF-8?q?=E6=89=BE=E4=B8=8D=E5=88=B0=E7=94=9F=E6=88=90=E5=99=A8=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Connection.php | 16 ++++++++++++++++ library/think/db/Query.php | 3 +-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index f14e010b..b1f730bf 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -58,6 +58,8 @@ abstract class Connection protected static $event = []; // 查询对象 protected $query = []; + // 使用Builder类 + protected $builder; // 数据库连接参数配置 protected $config = [ // 数据库类型 @@ -148,6 +150,20 @@ abstract class Connection return $this->query[$model]; } + /** + * 获取当前连接器类对应的Builder类 + * @access public + * @return string + */ + public function getBuilder() + { + if (!empty($this->builder)) { + return $this->builder; + } else { + return $this->getConfig('builder') ?: '\\think\\db\\builder\\' . ucfirst($this->getConfig('type')); + } + } + /** * 调用Query类的查询方法 * @access public diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 45cdd432..26a52c85 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -124,8 +124,7 @@ class Query */ protected function setBuilder() { - $builder = $this->connection->getConfig('builder') ?: $this->connection->getConfig('type'); - $class = false !== strpos($builder, '\\') ? $builder : '\\think\\db\\builder\\' . ucfirst($builder); + $class = $this->connection->getBuilder(); $this->builder = new $class($this->connection, $this); }