diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index 38887b09..8987391c 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -226,13 +226,17 @@ abstract class Connection /** * 设置数据库的配置参数 * @access public - * @param string $config 配置名称 - * @param mixed $value 配置值 + * @param string|array $config 配置名称 + * @param mixed $value 配置值 * @return void */ - public function setConfig($config, $value) + public function setConfig($config, $value = '') { - $this->config[$config] = $value; + if (is_array($config)) { + $this->config = array_merge($this->config, $config); + } else { + $this->config[$config] = $value; + } } /** @@ -247,9 +251,10 @@ abstract class Connection public function connect(array $config = [], $linkNum = 0, $autoConnection = false) { if (!isset($this->links[$linkNum])) { - if (empty($config)) { - $config = $this->config; + if ($config) { + $this->setConfig($config); } + $config = $this->config; // 连接参数 if (isset($config['params']) && is_array($config['params'])) { $params = $config['params'] + $this->params; @@ -281,20 +286,6 @@ abstract class Connection return $this->links[$linkNum]; } - /** - * 获取当前数据库的驱动类型 - * @access public - * @return string - */ - public function getDriverName() - { - if ($this->linkID) { - return $this->linkID->getAttribute(PDO::ATTR_DRIVER_NAME); - } else { - return $this->config['type']; - } - } - /** * 释放查询结果 * @access public diff --git a/library/think/db/Query.php b/library/think/db/Query.php index d838dc39..33d2d1f6 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -59,7 +59,7 @@ class Query public function __construct(Connection $connection = null, $model = '') { $this->connection = $connection ?: Db::connect([], true); - $this->driver = $this->connection->getDriverName(); + $this->driver = $this->connection->getConfig('type'); $this->prefix = $this->connection->getConfig('prefix'); $this->model = $model; }