优化think/cache/driver/Db.php驱动,支持单独配置,兼容默认database配置

This commit is contained in:
huangdijia
2016-01-26 13:17:07 +08:00
parent 40d76a74b2
commit 298202984d

View File

@@ -29,7 +29,14 @@ class Db
protected $handler = null; protected $handler = null;
protected $options = [ protected $options = [
'db' => '', 'type' => '',
'dsn' => '',
'hostname' => '',
'hostport' => '',
'username' => '',
'password' => '',
'database' => '',
'charset' => '',
'table' => '', 'table' => '',
'prefix' => '', 'prefix' => '',
'expire' => 0, 'expire' => 0,
@@ -46,7 +53,7 @@ class Db
if (!empty($options)) { if (!empty($options)) {
$this->options = array_merge($this->options, $options); $this->options = array_merge($this->options, $options);
} }
$this->handler = \Think\Db::connect(); $this->handler = \think\Db::connect((!empty($this->options['hostname']) || !empty($this->options['dsn'])) ? $this->options : []);
} }
/** /**