connect to multiple databases |
[eluser]Unknown[/eluser]
This works, but if you are using two databases in the same model (or the same controller, in different models) you will need to call 'db_select' before call any Active Record or Query because maybe other model has initialized another database after you. In other words, CI automatically selects the last initialize database and do not select it before any action, so if you are using two database in the same request be sure to add 'db_select' before do any action with database in all models. CI is not prepare for this case. Sample code in one Model: Code: class MyForumModel extends CI_Model { Alternative: Reading this StackOverflow Question, you can set 'pconnect' to FALSE (each action will do a new connection to DB, so this workaround is not very good for performance) or hack CI code (Remember to set charset encoding and collation too if charset or collation are different between databases!) Suggestion for CI Developers: Add a configuration parameter 'multiple_databases = TRUE' in database.php configuration file in order to add the hacking to code to DB_driver.php. I did it in my code ;-P |
Messages In This Thread |
connect to multiple databases - by El Forum - 02-16-2010, 03:27 AM
connect to multiple databases - by El Forum - 02-16-2010, 03:38 AM
connect to multiple databases - by El Forum - 02-16-2010, 03:40 AM
connect to multiple databases - by El Forum - 02-16-2010, 04:12 AM
connect to multiple databases - by El Forum - 02-24-2010, 08:47 PM
connect to multiple databases - by El Forum - 04-17-2012, 06:00 AM
connect to multiple databases - by El Forum - 07-10-2012, 08:50 AM
connect to multiple databases - by El Forum - 08-02-2012, 03:35 AM
connect to multiple databases - by El Forum - 08-15-2012, 07:45 AM
connect to multiple databases - by El Forum - 12-18-2013, 11:30 PM
connect to multiple databases - by El Forum - 07-03-2014, 06:38 AM
|