php - Not able to set multiple connections in laravel -


i want set multiple connections in laravel application.

i tried using database.php is:

'default' => env('db_connection', 'mysql'), 'connections' => [      'mysql' => [         'driver' => 'mysql',         'host' => env('db_host', 'localhost'),         'port' => env('db_port', '3306'),         'database' => env('db_database', 'reports_db'),         'username' => env('db_username', 'root'),         'password' => env('db_password', 'pass'),         'charset' => 'utf8',         'collation' => 'utf8_unicode_ci',         'prefix' => '',         'strict' => false,         'engine' => null,     ],      'mysql1' => [         'driver' => 'mysql',         'host' => env('db_host', 'localhost'),         'port' => env('db_port', '3306'),         'database' => env('db_database', 'a2z'),         'username' => env('db_username', 'root'),         'password' => env('db_password', 'root'),         'charset' => 'utf8',         'collation' => 'utf8_unicode_ci',         'prefix' => '',         'strict' => false,         'engine' => null,     ], ], 

and .env

db_connection=mysql db_host=127.0.0.1 db_port=3306 db_database=reports_db db_username=root db_password=pass   cl_db_connection=mysql1 db_host=127.0.0.1 db_port=3306 db_database=a2z db_username=root db_password=root 

inside controller

 public function index()     {         $ad= new ad;          $ad->setconnection('mysql1');         $ad =  ad::get();         echo $job;       } 

but not able set mysql1 connection.can please tell me how achieve this?

you using same connection parameters both time using same env values in database.php:

your .env file should contain this:

db_connection=mysql db_host=127.0.0.1 db_port=3306 db_database=reports_db db_username=root db_password=pass   two_db_connection=mysql1 two_db_host=127.0.0.1 two_db_port=3306 two_db_database=a2z two_db_username=root two_db_password=root 

and database.php should this:

'default' => env('db_connection', 'mysql'), 'connections' => [      'mysql' => [         'driver' => 'mysql',         'host' => env('db_host', 'localhost'),         'port' => env('db_port', '3306'),         'database' => env('db_database', 'reports_db'),         'username' => env('db_username', 'root'),         'password' => env('db_password', 'pass'),         'charset' => 'utf8',         'collation' => 'utf8_unicode_ci',         'prefix' => '',         'strict' => false,         'engine' => null,     ],      'mysql1' => [         'driver' => 'mysql',         'host' => env('two_db_host', 'localhost'),         'port' => env('two_db_port', '3306'),         'database' => env('two_db_database', 'a2z'),         'username' => env('two_db_username', 'root'),         'password' => env('two_db_password', 'root'),         'charset' => 'utf8',         'collation' => 'utf8_unicode_ci',         'prefix' => '',         'strict' => false,         'engine' => null,     ], ], 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -