We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Multiple Databases in a plugin

Development and Programming

sjcallan's avatar
sjcallan
10 posts
15 years ago
sjcallan's avatar sjcallan

Hi Guys, Let me apologize ahead of time, I am new to EE plugin development. I have a codeigniter background and I’m trying to use that knowledge in building some plugins.

Here is my problem: I am building a plugin that involves a corporate server environment and multiple databases. I need to query some of the data in those other databases. In CI to load multiple databases I added them to the config file then loaded them in my model via:

$this->db_1 = $this->load->database("db_1");
$this->db_1->get("table_name");

With EE I added them to the database file and the code works with:

$this->EE =& get_instance();
$this->db_1 = $this->EE->load->database("db_1");
$this->db_1->get("table_name");

With one database on top of the default EE database this works, but if I try to load multiple databases this way they seem to get confused and throw errors that the tables do not exist. Looking at the error, EE is trying to get the table from the wrong database.

Any help would be greatly appreciated.

Thanks.

       
soundseller's avatar
soundseller
52 posts
15 years ago
soundseller's avatar soundseller

EE noob here. Got some experience with Codeigniter. Have you managed to get it working? What’s the recommend way in EE to connect to multiple databases?

Thnx

       
soundseller's avatar
soundseller
52 posts
15 years ago
soundseller's avatar soundseller

Anybody?

       
soundseller's avatar
soundseller
52 posts
14 years ago
soundseller's avatar soundseller

Kinda disappointed by the EE forum. The codeigniter forum has always been very active and I kind of hoped for the same over here :( Oh well…

       
Victor Michnowicz's avatar
Victor Michnowicz
95 posts
14 years ago
Victor Michnowicz's avatar Victor Michnowicz

I don’t think you need the “$this” in there. Also, I believe you have to pass “TRUE” as your second parameter. Additionally, the code you listed will only work if you have the configuration settings for “db_1” in your database config file. Try something like this:

$dsn = 'dbdriver://username:password@hostname/database';
$db_1 = $this->EE->load->database($dsn, TRUE);

I’ve never used this feature of CI before, however, so I’m just pulling this info from the CI user guide.

       
soundseller's avatar
soundseller
52 posts
14 years ago
soundseller's avatar soundseller

I will try it out. Thnx for your reply!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.