Reputation: 136
I have and database of my project configured in another system. And I want to set connection details of another system.
I have tried to set database connection details of .env file which contain another system host, port, database name, username, and password.
DB_HOST=192.168.1.111
DB_PORT=3306
DB_DATABASE=database_name
DB_USERNAME=username
DB_PASSWORD=password
Upvotes: 0
Views: 138
Reputation: 9693
Put these things in you .env file and after that config/database.php
'mysqlRemote' => [
'driver' => 'mysql',
'host' => env('DB_REMOTE_HOST', '127.0.0.1'),
'port' => env('DB__REMOTE_PORT', '3306'),
'database' => env('DB_REMOTE_DATABASE', 'forge'),
'username' => env('DB_REMOTE_USER', 'forge'),
'password' => env('DB_REMOTE_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
now you can use this connection like
$data = DB::connection('mysqlRemote')->select( DB::raw('SELECT * FROM `table` ORDER BY id DESC LIMIT 10') );
Upvotes: 2