I have a series of databases named server_1 to server_100. Based on the URL parameter that the users select, I would like to connect to that database. Is there a way to accomplishing this without defining 100 separate connections in .env?
1 Answer
You have to change database connection on fly and also dont forget to purge connection.
Config::set("database.connections.mysql.host", "127.0.0.1");
Config::set("database.connections.mysql.database", "database_name");
Config::set("database.connections.mysql.username", "username");
Config::set("database.connections.mysql.password", "password");
DB::purge('mysql');
2 Comments
timyc
Are the configurations saved until script execution is complete, or is it saved until the DB is purged again?
Romik Makavana
It must require to purge connection, when ever you change.
tenancyconcept in laravel tenancy.dev