改进当数据库驱动类型使用完整命名空间的时候 Query类的builder方法的问题

This commit is contained in:
thinkphp
2016-08-05 10:34:54 +08:00
parent 51b5c4ae37
commit ac528e0680
2 changed files with 5 additions and 3 deletions

View File

@@ -105,6 +105,8 @@ abstract class Connection
'auto_timestamp' => false, 'auto_timestamp' => false,
// 是否需要进行SQL性能分析 // 是否需要进行SQL性能分析
'sql_explain' => false, 'sql_explain' => false,
// Builder类
'builder' => '',
]; ];
// PDO连接参数 // PDO连接参数

View File

@@ -34,7 +34,7 @@ class Query
// 数据库Connection对象实例 // 数据库Connection对象实例
protected $connection; protected $connection;
// 数据库驱动类型 // 数据库驱动类型
protected $driver; protected $builder;
// 当前模型类名称 // 当前模型类名称
protected $model; protected $model;
// 当前数据表名称(含前缀) // 当前数据表名称(含前缀)
@@ -59,7 +59,7 @@ class Query
public function __construct(Connection $connection = null, $model = '') public function __construct(Connection $connection = null, $model = '')
{ {
$this->connection = $connection ?: Db::connect([], true); $this->connection = $connection ?: Db::connect([], true);
$this->driver = $this->connection->getConfig('type'); $this->builder = $this->connection->getConfig('builder') ?: $this->connection->getConfig('type');
$this->prefix = $this->connection->getConfig('prefix'); $this->prefix = $this->connection->getConfig('prefix');
$this->model = $model; $this->model = $model;
} }
@@ -357,7 +357,7 @@ class Query
protected function builder() protected function builder()
{ {
static $builder = []; static $builder = [];
$driver = $this->driver; $driver = $this->builder;
if (!isset($builder[$driver])) { if (!isset($builder[$driver])) {
$class = false !== strpos($driver, '\\') ? $driver : '\\think\\db\\builder\\' . ucfirst($driver); $class = false !== strpos($driver, '\\') ? $driver : '\\think\\db\\builder\\' . ucfirst($driver);
$builder[$driver] = new $class($this->connection); $builder[$driver] = new $class($this->connection);