CodeIgniter Forums
Problem with instance of CI database class - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Problem with instance of CI database class (/showthread.php?tid=11592)



Problem with instance of CI database class - El Forum - 09-15-2008

[eluser]LuckyFella73[/eluser]
hello all,

I have a problem working with an instance of the CI database class.

I followed a tutorial of "Bramme" -> a basic login class (named "Auth").
In the class (Auth.php) an instance of the database class is loaded:
Code:
# first lines cut
function Auth($props = array())
    {
        $this->CI =& get_instance();
        
        # Load additional libraries, helpers, etc.
        $this->CI->load->library('session');
        $this->CI->load->database();
# rest fo code here

Within one function, I'm able to access my database, for example:
Code:
$this->CI->db->where('vorname', $this->vorname);
        $this->CI->db->where('nachname', $this->nachname);
        $this->CI->db->where('mitgliedsnummer', $this->mitgliedsnummer);
        $this->CI->db->where('geburtsdatum', $this->geburtsdatum);
        
        $query = $this->CI->db->get($this->usertable);

I added a method to the class (a set new password function) and can't access
the db anymore using the same synthax. In the new method I tried:
Code:
$this->CI->db->where('mitgliedsnummer', $this->session->userdata('mitgliedsnummer'));

I just get an error message at this line:
Quote:Fatal error: Call to a member function on a non-object in ...


Any ideas what I'm doing wrong?


Problem with instance of CI database class - El Forum - 09-15-2008

[eluser]drewbee[/eluser]
Your error isn't with the database, but the session method call.

Your calling:
Code:
$this->session->userdata('mitgliedsnummer')

Should be
Code:
$this->CI->session->userdata('mitgliedsnummer')



Problem with instance of CI database class - El Forum - 09-15-2008

[eluser]LuckyFella73[/eluser]
ähem ... sorry for beeing blind.


thank you Drewbee!


Problem with instance of CI database class - El Forum - 09-15-2008

[eluser]drewbee[/eluser]
No worries Smile It seems it's always the easy stuff that is always the hardest to find!