Welcome Guest, Not a member yet? Register   Sign In
use active records in library
#1

Hello,
i'm writing my personal library for Users.
but i have a problem trying to query my db.
is wrong call db from Lib?

PHP Code:
Class User
{
 
   public function __construct(){
 
      
    
}
 
   
   
    
    public 
function userExists($id){
 
       $query $this->db->get_where('users', array('id' => $id));
 
       $number $query->num_rows();
 
       if($number 0)
 
           return true;
 
       else
 
           return false;
    }
 
       



obviously in my controller i loaded the lib with 

PHP Code:
$this->load->library('user'); 

the error is

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: User::$db

Filename: libraries/User.php

Line Number: 28

Backtrace:

File: /web/htdocs/www.mysite.com/home/API/application/libraries/User.php
Line: 28
Function: _error_handler

File: /web/htdocs/www.mysite.com/home/API/application/controllers/User_authentication.php
Line: 29
Function: userExists

File: /web/htdocs/www.mysite.com/home/API/index.php
Line: 315
Function: require_once


Fatal error: Call to a member function get_where() on a non-object in /web/htdocs/www.mysite.com/home/API/application/libraries/User.php on line 28
A PHP Error was encountered

Severity: Error

Message: Call to a member function get_where() on a non-object

Filename: libraries/User.php

Line Number: 28

Backtrace:

is a good way?
Reply


Messages In This Thread
use active records in library - by Valerekk - 10-21-2017, 07:10 PM
RE: use active records in library - by enlivenapp - 10-21-2017, 07:41 PM
RE: use active records in library - by Valerekk - 10-22-2017, 06:22 AM
RE: use active records in library - by InsiteFX - 10-22-2017, 03:29 AM
RE: use active records in library - by InsiteFX - 10-23-2017, 08:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB