CODEIGNITER rufen Sie an eine member-Funktion num Zeilen auf boolean

bitte ich habe ein Problem mit codeigniter. wenn ich mich einloggen will, hier ist das Ergebnis:

Fatal error: Call to a member function num_rows() auf bool in D:\xampp\htdocs\procurementSys\application\models\login_model.php in Zeile 19

Unten tho-code für die jeweilige Datei:

  <?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;
   //}
}

 }

 ?>

Suchte ich weiter nach einer Lösung und fand diesen post (Rufen Sie an eine member-Funktion num_rows() ein boolean) . Es gab mir eine Idee, aber keine echte Hilfe. Dank

plz Erwähnung Fehler in der Funktion ????
Es scheint, dass die variable $query dass Sie versuchen, ein Objekt und eine Methode aufrufen, ist in der Tat ein boolescher Wert, nicht ein Objekt. Sie können einfach verwenden, var_dump, um zu sehen, für Ihr selbst, um zu Debuggen. In Ihrem Fall bedeutet dies normalerweise, dass die obige Abfrage fehlgeschlagen, so sollten Sie Forschung Fehlerbehandlung.
ja, var_dump@$query zurückgegeben werden BOOL(FALSE). wie Sie das lösen. was sollte ich auch als code, um mir zu helfen checken die Fehler?
db->get() können FALSE zurückgeben, die in der Regel zeigt ein problem mit der sql-Anweisung. Für mich ist es in der Regel etwas in der where Teil der Aussage. Ich habe bekommen in die Gewohnheit, mit if($query){.. bevor Sie es verwenden, zB. $row = $query->row();

InformationsquelleAutor referag | 2016-02-25

Schreibe einen Kommentar