In my database.php , I have two databases installed.
'db1' => array( 'driver' => 'pgsql', 'host' => 'localhost', 'database' => 'db1', 'username' => 'root', 'password' => 'password', 'charset' => 'utf8', 'prefix' => '', 'schema' => 'public', ), 'db2' => array( 'driver' => 'pgsql', 'host' => 'localhost', 'database' => 'db2', 'username' => 'root', 'password' => 'password', 'charset' => 'utf8', 'prefix' => '', 'schema' => 'public', ),
Thus, by default, db1 first set as the base database. Now I want to switch the default database to "db2" by selecting an option from the "Select" drop-down list. This will make an AJAX mail request to the controller method in which I do
public function postChangeDb() { $db = Input::get('db'); Config::set('database.default', $db); }
Once this is done, I am "refreshing" the page, but the connection is still in "db1".
I also tried the following
public function getTest() { Config::set('database.default', 'db1'); $users = User::all(); echo sizeof($users);
And it works fine, and it successfully switches the database. Is the per-request switch basic?
php laravel
ericbae
source share