Echo mysql查询[关闭]

I am using the following function in a model:

function login($email,$password)
{
    $this->db->where("email",$email);
    $this->db->where("password",$password);

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

    if($query->num_rows()>0)
    {
        foreach($query->result() as $rows)
        {
            //add all data to session
            $newdata = array(
                'user_id'  => $rows->id,
                'user_name'  => $rows->username,
                'user_email'    => $rows->email,
                'logged_in'  => TRUE,
            );
        }
        $this->session->set_userdata($newdata);
        return true;
    } else { 

    }
    return false;
}

When I enter the details it should not fail. There is no db error, I have debug turned on.

QUESTION: Is it possible to echo the query that is being sent so I can see what its trying to do and thus why its failing.

yes..

try this

 echo $this->db->last_query();

after you make a query....

this print the query that was last made..

so if you want to get the last query,do

 $query=$this->db->get("users");
 echo $this->db->last_query();

Do this:

echo $this->db->last_query();

And see the query.

use this

print_r($query);

after

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