Search code examples
phpcodeigniterdatabase-connectionphpactiverecord

CodeIgniter with PHP Activerecord Spark Multiple Databases


So far I really enjoy how CodeIgniter plays together with PHP ActiveRecord ORM tool,

How would I go about specifying which connection to use in my models?

My config/database.php file has 2 connections set up: $db['default'] and $db['myOtherDb']

Thanks


Solution

  • UPDATE:

    I found my solution by invoking the autocomplete in my IDE inside my ActiveRecord Model and checking the available methods/properties, one of the properties is $connection and we can set it to the connection that we want to use, so in my model:

    public static $connection = 'byOtherDb';