-4

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.

Alvin Wong
  • 12,210
  • 5
  • 51
  • 77
StudioTime
  • 22,603
  • 38
  • 120
  • 207
  • maybe in the db class you can echo the query before the execute_query statement – Nagasaki May 10 '13 at 09:40
  • possible duplicate of http://stackoverflow.com/questions/210564/pdo-prepared-statements/210693#210693 – Robert May 10 '13 at 10:06
  • 1
    I have downvoted your question because you have posted it 3 times:http://stackoverflow.com/questions/16478481/ci-show-database-error-or-fail http://stackoverflow.com/questions/16477979/ci-show-me-what-went-wrong – despina May 10 '13 at 13:50

3 Answers3

2

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();
bipen
  • 36,319
  • 9
  • 49
  • 62
2

Do this:

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

And see the query.

Vijaya Pandey
  • 4,252
  • 5
  • 32
  • 57
0

use this

print_r($query);

after

$query=$this->db->get("users");
bipen
  • 36,319
  • 9
  • 49
  • 62
mathew
  • 193
  • 1
  • 5