如何在laravel-5中連接兩個數據庫以及如何從db中獲取數據。在laravel中連接兩個數據庫
我知道兩一件事對於
在配置/數據庫這樣設置。
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'larashop'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
'mysql2' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'larashop2'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
這裏有一些教程。我從這個參考。 http://fideloper.com/laravel-multiple-database-connections https://laracasts.com/discuss/channels/general-discussion/hitting-multiple-databases-dinamically-with-laravel?page=1 –
此代碼是okk,但從.evn刪除連接代碼。 – Kanu