From 17c76a41c79e4d948a135ca3d336f90193573ded Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 2 Aug 2016 15:38:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BB=E7=9A=84driver?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E8=AE=BE=E7=BD=AE=20=E5=88=A0=E9=99=A4Connec?= =?UTF-8?q?tion=E7=B1=BB=E7=9A=84getDriverName=E6=96=B9=E6=B3=95=20?= =?UTF-8?q?=E6=94=B9=E8=BF=9Bconnect=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Connection.php | 31 +++++++++++-------------------- library/think/db/Query.php | 2 +- 2 files changed, 12 insertions(+), 21 deletions(-) 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; }