[eluser]warrennz[/eluser]
From my basic understanding, PHP caches the MySQL DSN string. When you change database and attempt to use a different table, it still attempts to use that new table in the previous database. One way (not too sure how...'good' this practice is) I got around this was to create 2 very different DSN's so that php would cache them individually.
For example on the database config I would have
config/database.php
Code:
$active_group = "default";
$active_record = TRUE;
$db['default']['hostname'] = "127.0.0.1";
$db['default']['username'] = "user1";
$db['default']['password'] = "pass1";
$db['default']['database'] = "table1";
$db['seconddb']['hostname'] = "localhost";
$db['seconddb']['username'] = "user2";
$db['seconddb']['password'] = "pass2";
$db['seconddb']['database'] = "table2";
$db['seconddb']['dbdriver'] = "mysql";
'default' is my default config, and would be accessed via the normal $this->db in most places. Localhost and 127.0.0.1 are obviously pointing to the same host and user1 and user2 have exactly the same privileges on the database. The difference in DSN is enough to make php cache separately.
If I had a model that accesses a table in a different database, I would add a 2nd db property in the constructor
Code:
class radius extends Model {
function radius_model()
{
parent::Model();
$this->asidb = $this->load->database('seconddb', TRUE, TRUE);
}
function do_something()
{
return $this->asidb->where('something')->get('some_table')->result_array();
}
}
Again, I'm to sure if this is a good practice or not but was the only way I managed to get around my multiple database issues.
Also, I don't think ORM is designed to support multiple databases. At least in my experience.