The FuelPHP documentation does not include information on how to use the DB class to specify connections, which would allow me to then control multiple database connections. Any idea on how to accomplish this? Google search shows evidence of a Database_Connection class, but no information on how it might be used.
Asked
Active
Viewed 3,323 times
1 Answers
1
First place to start would be reading https://github.com/fuel/core/blob/1.1/master/classes/database/connection.php .. It looks like you will have to write something similar to:
$db2 = DB::instance( 'second_connection' );
Where second_connection
is configured as per example : http://fuelphp.com/docs/classes/database/introduction.html
When you first time you execute that function, it will create new instance. Afterwards when you use the same line , it will just pick opened connection from the registry .. Essentially, it's same old procedural code with global array of DB connections, just wrapped in fake OO code.

pconcepcion
- 5,591
- 5
- 35
- 53

tereško
- 58,060
- 25
- 98
- 150
-
1.2 : $db2 = Database_Connection::instance('second_connection'); or $results = /.. query ../->execute('second_connection'); – younes0 Aug 21 '12 at 09:50
-
Yeah, seems like the have changed the class names from `DB` to `Database_Connection` when moving fro v1.1 to v1.2 release. – tereško Aug 21 '12 at 09:54
-
The DB class still exists, and it's the static interface to the DB drivers. DB::instance() afaik never existed. – WanWizard Sep 10 '12 at 16:36