Connecting to database from config - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Connecting to database from config (/showthread.php?tid=25362) |
Connecting to database from config - El Forum - 12-09-2009 [eluser]blasto333[/eluser] Code: if(isset($_SERVER['HTTP_HOST'])) How can I use code ignitor to connect to the database from a config file? Connecting to database from config - El Forum - 12-09-2009 [eluser]stuffradio[/eluser] Why not just use the database.php file in the config folder? Connecting to database from config - El Forum - 12-09-2009 [eluser]theprodigy[/eluser] I would assume, the same way you would with custom libraries Code: $CI =& get_instance(); or the old fashioned PHP way Code: $link = mysql_connect( $server, $username, $password ) Connecting to database from config - El Forum - 12-09-2009 [eluser]Colin Williams[/eluser] Well, you don't want to hide data-related functionality in a config file. It should be in a model. So, do this: 1. Use config files for default values. 2. In the Controller's constructor (or a hook), use a model to get custom settings, iterate over the result, and use the config class methods to update the values. Quote:I would assume it works the same way as with custom libraries I'm pretty certain the Config class is loaded before the controller, so no, that would not work. get_instance() is only effective (and available) at a certain point in the execution of the framework |