![]() |
DB inside Library - 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: DB inside Library (/showthread.php?tid=10791) |
DB inside Library - El Forum - 08-12-2008 [eluser]cmgmyr[/eluser] Hello, Is there a way I can get the DB connection into a library? The idea is to load a "startup" library when the system finishes loading, this includes making db queries and adding the values to the config array. I can't seem to figure out how to get the connection into the library. Is there any way to make this work? Or do you have a similar idea that I can accomplish the same thing? Thanks in advance! -Chris DB inside Library - El Forum - 08-12-2008 [eluser]Colin Williams[/eluser] $this->ci =& get_instance() $this->ci->db->get(); DB inside Library - El Forum - 08-12-2008 [eluser]cmgmyr[/eluser] Thanks, that worked out great! DB inside Library - El Forum - 12-23-2008 [eluser]jwindhorst[/eluser] I was doing something very similar when I came across this post and though I would add my own 2 cents. Adding in the instance of the CI object this way, makes all that CI nonsense spit out when you print_r, or var_dump the library object. I find this to be mildly annoying, and so I've decided to instantiate the CI object inside each method: Code: function load_assets() After seeing this post however, I'm wondering about performance. I could deal with the annoyance of having the extra info in the object, if there were a performance boost to doing it that way. Anyone out there so good in CI that they can explain to me the performance benefits of using one method over the other? Thanks |