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); }