Alan James Tue Oct 30 16:12:27 -0400 2012

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?


Mr. Carl Fri Nov 02 16:26:16 -0400 2012

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

Alan James Sat Nov 03 21:05:53 -0400 2012

I haven't tested this fully on my site yet, but that looks to be exactly what I was searching for.

Thank you.

oliver russell Thu Nov 02 02:56:53 -0400 2017

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)