Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Multiple Database Connections
  • I'm wondering how to specify the database connection using the DB class. The documentation doesn't include information on how to control what database you are connecting to.
  • The database class provides a set of static methods to access the database, which all use the current instance, i.e. the one that is defined as active in your database config file. You can create a specific db instance using
    $db = \Database_Connection::instance('myowndb'); // where 'myowndb' is a section in your database config
    

    You can also pass the specific database as a parameter of the execute() method:
    // pass a specific database object
    $result = \DB::select()->from('users')->where('id', 1)->execute($db);
    
    // or use the name and have it be created on the fly
    $result = \DB::select()->from('users')->where('id', 1)->execute('myowndb');
    

    This syntax is document here: http://fuelphp.com/docs/classes/database/usage.html#running-queries

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion