Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
multi database
  • hi
    i need connect 2 database with \DB class and get info from theme
    db1 is fuelphp main database
    db2 is email server database (module)
    how can i do that?
    can i use fuelphp model with db2?

  • HarroHarro
    Accepted Answer
    There are several ways.

    You can pass the name of the database as configured to the execute() method of a DB call:

    $record = DB::select()->from('table')->where('id', 1)->execute('otherdb');

    For ORM and Model_Crud, you can define the database to be used in a model property:

    protected static $_connection = 'otherdb';

    ORM and Model_Crud can also split reads and writes, so you can also do:

    protected static $_connection = 'readonlydb';
    protected static $_write_connection = 'readwritedb';

  • hi Harro,
    i define
    protected static $_connection = 'email'; in my model
    and use this query in controller :
    data['inbox'] = Model_Email::query()
                    ->related('account')
                    ->where('account.accountaddress', '=', $current_user->email)
                    ->get();
    and send me this error :
    Fuel\Core\FuelException [ Error ]:
    Database type not defined in "email" configuration or "email" configuration does not exist


    where i define email connection info?



  • HarroHarro
    Accepted Answer
    In your db.php.

    For the default database definition, Fuel provide a lot of defaults, but for others you need to define that yourself. There is an example of a full config in the docs: http://fuelphp.com/docs/classes/database/introduction.html#/configuration

Howdy, Stranger!

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

In this Discussion