Take look at Configuration Setup Multi-connections This will show you how to setup different model types (user, book, etc) for different database.
If your talking about setting different database for the SAME model (user to database A, user to database B) then you should take look at the "User Contributed Notes" (User comments) in PHP Manual for Static Keyword
I haven't tested this fully on my site yet, but that looks to be exactly what I was searching for.
Thank you.
Alan James wrote:
I'm sure someone has asked this question but I can't find the answer.
How would one connect to a different database for each model they create?
Using this code for multiple database connection in codeigniter (https://www.cloudways.com/blog/connect-multiple-databases-codeigniter/)
function db_calling_model_method()
{
$otherdb = $this->load->database('anotherdb', TRUE); // the TRUE paramater tells CI that you'd like to return the database object.
$query = $otherdb->select('column_one, column_two')->get('table');
var_dump($query);
}
(1-3/3)
Subject: Multiple Database Connections
I'm sure someone has asked this question but I can't find the answer.
How would one connect to a different database for each model they create?