0

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
Prafulla Kumar Sahu
  • 9,321
  • 11
  • 68
  • 105
Vivek Solanki
  • 136
  • 1
  • 13

1 Answers1

2

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') );
Prafulla Kumar Sahu
  • 9,321
  • 11
  • 68
  • 105