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
trueas the second parameter and capture the output in a variable.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_oneandgroup_twothese are database setting groups (in your config file you normally only have thedefaultgroup).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
and you can close one of the connections by using
$DB2->close();or$DB1->close();More information can be found in the userguide