Part of the EllisLab Network
   
 
database() on a non-object
Posted: 04 July 2009 01:42 PM   [ Ignore ]  
Grad Student
Rank
Total Posts:  49
Joined  07-03-2009

Hi everyone,

I’m creating a custom library in the applications/library folder and when I try to use the database, it gives me this error:

Fatal error: Call to a member function where() on a non-object in /public_html/stage/system/application/libraries/User.php on line 181

$this->db->where($this->tblUser, $user);
        
$this->db->where($this->tblUserPass, $pass);
        
$this->db->limit(1,0);
        
$query = $this->db->get($this->tbl);

        if (
$query->num_rows() > 0)
        
{

        }
Profile
 
 
Posted: 04 July 2009 01:50 PM   [ Ignore ]   [ # 1 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  3782
Joined  04-25-2008

You need to load the database before you can use it.

$this->load->database();

Alternatively, you can autoload it via the autoload.php file.

 Signature 

Remember the 8 Ps: Perfect Planning and Prior Preparation Prevents Piss-Poor Performance.


Not sure where to start with your project? Need some inspiration? Check out my CodeIgniter Resources thread

Profile
 
 
Posted: 05 July 2009 02:25 PM   [ Ignore ]   [ # 2 ]  
Grad Student
Rank
Total Posts:  49
Joined  07-03-2009

It worked, thanks!

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 120322 Total Logged-in Users: 53
Total Topics: 126442 Total Anonymous Users: 3
Total Replies: 664918 Total Guests: 495
Total Posts: 791360    
Members ( View Memberlist )