Welcome Guest, Not a member yet? Register   Sign In
DB inside Library
#1

[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
#2

[eluser]Colin Williams[/eluser]
$this->ci =& get_instance()

$this->ci->db->get();
#3

[eluser]cmgmyr[/eluser]
Thanks, that worked out great!
#4

[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()
{
    $ci=& get_instance();
}

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




Theme © iAndrew 2016 - Forum software by © MyBB