Currently there is not way to create dynamic connections on Laravel other than specifying a config key and using
`DB::connection('key')
It would be good to specify the connection information dynamically, something like this
DB::createConnection(array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'dbname',
'username' => 'dbuser',
'password' => 'dbpass',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
)
Config::set('database.connections.key', array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'dbname',
'username' => 'dbuser',
'password' => 'dbpass',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
));
With that DB::connection('key');
would just work.
crynobone, thanks for this. Does it require specify any config info named key
on database.php? or will it just create this config on the fly?
You can create the config on the fly, it would just be appended to "database.connections" config.
Thanks, that works. Appreciate your help
Most helpful comment
With that
DB::connection('key');
would just work.