I had developed a application in codeigniter. I had a forum like section in my application. For that I would likes to create a separate database to that controller.
So that I can maintain the site and database very easily. My question is possible in codeigniter to assign a database to a single controller ?
Thanks
As mentioned in manix's answer you can pass the settings to the database library constructor.
However what was missed is that you must specify true
as the second parameter and capture the output in a variable.
$DB1 = $this->load->database('group_one', TRUE);
$DB2 = $this->load->database('group_two', TRUE);
Failure to do so means you can only work with one database at a time as it replaces the database connection instead of opening a new one!
Note that we are passing in the strings group_one
and group_two
these are database setting groups (in your config file you normally only have the default
group).
You can replace the group name with an array of config options, but it is better to use the groups!
You can then run your queries as
//query against first database
$DB1->select(...
//query against second database
$DB2->select(...
and you can close one of the connections by using $DB2->close();
or $DB1->close();
More information can be found in the userguide