laravel 动态链接数据库

作者: JONE 分类: 编程 发布时间: 2021-01-14 18:36
use Illuminate\Support\Facades\DB;

\Config::set("database.connections.mysql2", [
    'driver' => 'mysql',
    'port' => '3306',
    "host" => "localhost",
    "database" => "web",
    "username" => "root",
    "password" => "root"
]);

$a = DB::connection('mysql2')->select('select * from oss_cifs');

通过动态添加数据库配置,然后链接指定的数据库,尽量新增而不是覆盖原有数据库配置