Fatal error: Call to undefined method CI_DB_mysql_driver::result() - CodeIgniter

hi guys

I have CodeIgniter error below,


  function check_email()
  {
    $query = $this->db
      ->select('email')
      ->from('user')
      ->where('email', $this->input->post('email'));

    return $query->result();
  }

Can you tell me why is it when i include th result() method it show an error mesage?

Thanks in advancd.

Apparently, that Class doesn’t have that method.

And that could be the reason for your error.

You probably want execute() instead ?

 function check_email()
  {
    $query = $this->db
      ->select('email')
      ->from('user')
      ->where('email', $this->input->post('email'));

    return $query->execute();
  }

Regards,
Márcio

As mentioned by oikram the $query Object does not have a result() Method .

Try this:



//================================
function check_email()
{
    $query = $this->db
      ->select('email')
      ->from('user')
      ->where('email', $this->input->post('email'));
       
    // return $query->result();

    $query = $this->db->get();

    if ($query->num_rows())
    {   
    	return $query->result();
    }else{
    	echo 'Big Problem';
        die;
    }

}//endfunc


.

The method name is rather ambiguous, are you checking if the email exists? If so, you should be returning a bool.

<?php
function email_registered($email){
  $query = $this->db->get_where('user', array('email' => $email));
  return 0 < $query->num_rows();
}

if(email_registered($this->input->post('email'))){
  #email is registered
}
?>

:slight_smile: