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.
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.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.