方法一:
在application/config.php 文件中新增数据库连接配置文件( 应用设置之前 ):
<?php
use think\Env;
return [
// +----------------------------------------------------------------------
// | 第二个数据库设置
// +----------------------------------------------------------------------
"db_second" => [
// 数据库类型1
'type' => 'mysql',
// 服务器地址
'hostname' => '127.0.0.1',
// 数据库名
'database' => 'db_second_name',
// 用户名
'username' => 'db_second_username',
// 密码
'password' => 'db_second_password',
// 端口
'hostport' => '3306',
// 连接dsn
'dsn' => '',
// 数据库连接参数
'params' => [],
// 数据库编码默认采用utf8
'charset' =>