Welcome Guest, Not a member yet? Register   Sign In
Database Connection
#1

[eluser]stewartf[/eluser]
Wondering how to connect to a database within a custom library. I attempted to use $this->load->database() which returned this : Undefined property: Cataloglib::$load.

So the question is, what did I do wrong?
#2

[eluser]stewartf[/eluser]
I added ' extends CI_Controller ' to the class and that worked. To take it a step further, is this a good practice?
#3

[eluser]cideveloper[/eluser]
I do it this way

Code:
public function __construct() {
    $this->CI =& get_instance();
}

public any_other_function(){
    $this->CI->load->database();
}


This is the way I have seen it done in most other big project using CI
#4

[eluser]stewartf[/eluser]
Very nice. Thank you.
#5

[eluser]danmontgomery[/eluser]
(Libraries shouldn't extend the controller)




Theme © iAndrew 2016 - Forum software by © MyBB