I want to do two Laravel connections with two databases in MySQL. So in my database.php file I have added this connection.
'mysql2' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'db2'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'PASSWORD2'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
And in my routes file I added this route
Route::get('/', function()
{
$users =DB::connection('mysql2')->select('select * from users')->get();
return $users;
});
But when I browse to get the result of the query
QueryException in Connection.php line 729:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'test.users' doesn't exist
I need someone helps me .
via JavaFan