mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
改进Query类的setBuilder方法 避免因自定义连接器类后找不到生成器类
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user