Laravel 动态切换数据库配置

$databases = app()['config']['database'];
$databases['connections']['dbname']['host'] = '127.0.0.1';
$databases['connections']['dbname']['username'] = 'root';
$databases['connections']['dbname']['password'] = '';
$databases['connections']['dbname']['database'] = 'db_xxx';
app()['config']['database'] = $databases;
\DB::connection('dbname')->reconnect();

 

你可能感兴趣的:(PHP)