如何在Laravel中获取数据库连接列表。我打算将连接名称加载到选择框中。
'connections' => [
'sqlsrv_auth' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'SQLEXPRESS'),
'database' => env('DB_DATABASE', 'auth_db'),
'username' => env('DB_USERNAME', 'sa'),
'password' => env('DB_PASSWORD', '1234'),
'charset' => 'utf8',
'prefix' => '',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'SQLEXPRESS'),
'database' => env('DB_DATABASE', 'main_db'),
'username' => env('DB_USERNAME', 'sa'),
'password' => env('DB_PASSWORD', '1234'),
'charset' => 'utf8',
'prefix' => '',
],
'sqlsrv_bpb' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', '192.168.1.1'),
'database' => env('DB_DATABASE', 'mirror'),
'username' => env('DB_USERNAME', 'sa'),
'password' => env('DB_PASSWORD', '1234'),
'charest' => 'utf8',
'prefix' => '',
]
],
答案 0 :(得分:2)
得到了..
use Config;
public function test() {
print_r(Config::get('database'));
}
答案 1 :(得分:0)
secondDb变量现在保持'sqlsrv_bpb'(连接名称)
的连接$secondDb = DB::connection('sqlsrv_bpb');