Support the ongoing development of Laravel.io →
posted 11 years ago
Database

Is there a package out there for Laravel that will allow creation of dynamic Oracle database connections?

My app requires the ability to store the Oracle database connection info in a MySQL database, then create the connection dynamically when that connection is needed. I can have connections to many different Oracle databases, so creating each connection in a config files is not practical for this application.

Any ideas?

Last updated 3 years ago.
0

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!

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.