#### 数据库切换
* 切换数据库(一)
~~~
$result = Db::connect('mysql:root:123456@127.0.0.1:3306/testA#utf8')->query('select * from user where age=18');
dump($result);
~~~
* 切换数据库(二)
~~~
$result =
Db::connect([
'type'=>'mysql',
'hostname'=>'127.0.0.1',
'database'=>'test',
'username'=>'root',
'password'=>'123456',
'hostport'=>'3306',
'params'=>[],
'charset'=>'utf8',
'prefix'=>'',
]
)
~~~
* 切换数据库(三)
~~~
application/config.php
$db1 = [
'type'=>'mysql',
'hostname'=>'127.0.0.1',
'database'=>'testA',
'username'=>'root',
'password'=>'123456',
'hostport'=>'3306',
'params'=>[],
'charset'=>'utf8',
'prefix'=>'',
],
$db2 = [
'type'=>'mysql',
'hostname'=>'127.0.0.1',
'database'=>'testB',
'username'=>'root',
'password'=>'123456',
'hostport'=>'3306',
'params'=>[],
'charset'=>'utf8',
'prefix'=>'',
],
Db::connect('db1')->query('select * from user where age=25');
~~~