Hi, it seems that you have same issue than I just had. This seem to work. In this case connection params are coming from session.
public static function CreateDatabaseConnection(){
Config::set('database.connections.dbconnection', array(
'driver' => 'mysql',
'host' => '10.0.3.2',
'port' => Session::get('db_port'),
'database' => Session::get('db_name'),
'username' => Session::get('db_user'),
'password' => Session::get('db_pswd'),
'charset' => 'utf8',
'collation' => 'utf8_swedish_ci',
'prefix' => '',
));
Config::set('database.default', 'dbconnection');
try{
$users = DB::select('SELECT * FROM users', array());
}catch(\Exception $e){
Log::error('CreateDatabaseConnection Exception:'.$e->getMessage());
return false;
}
return true;
}
After creating connection, you can use it as it default connection. If you want to keep your default connection as it is, just remove line: Config::set('database.default', 'dbconnection') and call your connection like this:
DB::connection('dbconnection')->table('users')->get();
Basically it's just how configuration seem to work, this is also worth of reading: http://laravel.com/docs/configuration Hope this helps!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community