• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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)


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.