![]() |
want to use multiple database. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: want to use multiple database. (/showthread.php?tid=49470) |
want to use multiple database. - El Forum - 02-20-2012 [eluser]Mistry007[/eluser] hi every one. I want to use multiple database in my project. one db for the testing and another for real data. I have gone through the database config now i have set the two connection in database.php file Code: $active_group = 'default'; Now i want to use it like if i run my test controller then it should take "xit_product_test" database. and if i run another controller then it will took the default database. now i have a little bit confustion for testing i have implemented unit testing which check the model functions. Do i have to change all model for multiple database. Any help will be appriciated.. Thanks want to use multiple database. - El Forum - 02-21-2012 [eluser]louisl[/eluser] Check in the index.php for the ENVIRONMENT constant, I think that was added in 2.0.1 Then just switch your ./application/config/database.php depending on the environment eg. Code: switch (ENVIRONMENT) { want to use multiple database. - El Forum - 02-21-2012 [eluser]CroNiX[/eluser] Actually, you create a subdirectory named after the environment and place the database.php config file (and other config files) in those. They will get loaded depending on the environment. No need for manual switching... /application/config/testing/config.php /application/config/testing/database.php /application/config/production/config.php /application/config/production/database.php http://ellislab.com/codeigniter/user-guide/libraries/config.html#environments |