(1)在connections下模仿mysql新加一个,值自己根据自己的配置改
'mysql_test' => [ 'driver' => 'mysql', 'host' => '127.0.0.1', 'port' => '3306', 'database' => 'db_database', 'username' => 'db_username', 'password' => 'db_password', ],
(2)也可以直接在接口了设置
DB::disconnect(); \Config::set("database.connections.mysql_test", [ 'driver' => 'mysql', 'host' => '127.0.0.1', 'port' => '3306', 'database' => 'db_database', 'username' => 'db_username', 'password' => 'db_password', ]);
$users = DB::connection("mysql_test")->table('users')->select(['id', 'name'])->first();
最新评论: