Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CODEIGNITER call to a member function num rows on boolean

please i have an issue with codeigniter. when i try to log here is the result:

Fatal error: Call to a member function num_rows() on boolean in D:\xampp\htdocs\procurementSys\application\models\login_model.php on line 19

Below tho code of the relative file:

  <?php


  class Login_model extends CI_Model {

//this function checks whether the username and the password is in the database or not
public function check_login($username, $password){

    $this->db->select('username, password, status');
    $array = array('username' => $username, 'password' => sha1($password),'status' => 'active');
    $this->db->where($array);
    $query = $this->db->get('user');

    if($query->num_rows() == 1) // if the affected number of rows is one
    {
        return true;
    }
    else
    {
        return false;
    }
}

//this function returns the status of the user to be used in authentication
public function user_login_data($username, $password){

    $this->db->select('status');
    $array = array('username' => $username, 'password' => sha1($password));
    $this->db->where($array);
    $query = $this->db->get('user');

    if($query->num_rows() == 1) // if the affected number of rows is one
    {
         $row = $query->row();
         return $row->status;
    }
  //        else
  //        {
  //            return false;
  //        }
}


public function user_role($username){ // this function gets the user's role from the database
     $this->db->select('role');
     $this->db->where('username', $username);
     $query = $this->db->get('user');
     $row = $query->row(0);

     return $row->role;
}

public function department($username){ // this function gets the user's department from the database
     $this->db->select('department');
     $this->db->where('username', $username);
     $query = $this->db->get('user');
     $row = $query->row(0); // returns the first row with an array of objects that is stored in the row variable

     return $row->department;
}

public function get_user_id($username){ // this function gets the user's department from the database
     $this->db->select('userID');
     $this->db->where('username', $username);
     $query = $this->db->get('user');
     $row = $query->row(0); // returns the first row with an array of objects that is stored in the row variable

     return $row->userID ;
}

public function fullname($username){
     $this->db->select('firstName, secondName');
     $this->db->where('username', $username);
     $query = $this->db->get('user');
     $row = $query->row(0);
     return $row;

  //            foreach($query->result() as $row) // returns the query as an array of objects
  //           {
  //                $data[] = $row; // equates the array of objects to an array variable
  //           }
  //        
  //           return $data;
   // }
}

 }

 ?>

I kept searching for a solution and found this post (Call to a member function num_rows() on boolean) . It gave me an idea but no real help. thanks

like image 851
referag Avatar asked May 11 '26 16:05

referag


1 Answers

I got this error with MySQL Strict Mode enabled. When I disable Strict Mode, error disappeared.

To check this mode is already enabled

SHOW VARIABLES LIKE 'sql_mode';

To make it disabled

SET GLOBAL sql_mode = 'NO_ENGINE_SUBSTITUTION';
like image 115
Rajitha Bandara Avatar answered May 14 '26 05:05

Rajitha Bandara



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!