Welcome Guest, Not a member yet? Register   Sign In
Multiple database connectivity
#1

[eluser]Sanjib Kumar Jena[/eluser]
Hi All,

I have integrated two databases in my site. I can able to access multiple database as bellow.

$this->DBOne = $this->load->database('default', TRUE);
$this->DBtwo = $this->load->database('another', TRUE);

But what's my problem is i have to write the above code in almost all of model constructor.
Is there any trick or method to get all the database objects automatically in the model or controller instead of writing the above code. I mean can we autoload the databases and get the database instances which will be available through out our program.
#2

[eluser]john_j[/eluser]
I think one way will be to put this in a class constructor and inherit it using extends where ever required.

if you want to go with autloading then you need to add them in application/config/autoload.php file. Refer the CI user guide regarding autoloading.
#3

[eluser]CroNiX[/eluser]
I believe you can only "autoload" one database connection.

Extend CI's core model class with MY_Model and put them in the constructor there. Then all of your other models would extend MY_Model (instead of CI_Model) and have those properties be available to them.

See the Extending Core Classes section




Theme © iAndrew 2016 - Forum software by © MyBB