5

Quite a simple thing to ask and must be discussed many times, but I still not able to get the result of $this->db->last_query();.

            $this->db->select('count(*) as totalverified,res_sales.upduser, employee.name');
        $this->db->from('res_sales');
        $this->db->join('employee','employee.user_id = res_sales.upduser');
        $this->db->where('date>=', $fromdate);
        $this->db->where('date<=', $todate);
        $this->db->where('verificationnumber<>', '');
        $this->db->where('verificationnumber<>', NULL);
        $this->db->group_by('res_sales.upduser');
        $this->db->group_by('employee.name');
        $q = $this->db->get();
        $str = $this->db->last_query();
        print_r($str);
        if ($q->num_rows() > 0)
        {
            return $q->row();
        }

        return FALSE;

Above is the code in my model function. I am not able to get the result as expected to want to see what the query is being run at backend.

Thanks. Danish

1
  • add die; or exit after your print_r($str) line Commented Jul 28, 2017 at 4:41

1 Answer 1

7

I figured out the problem. I have to write a statement just above my query i.e:

$this->db->save_queries = TRUE;

After this write your query and than write $this->db->last_query(); it is showing the last query now.

Sample:

$this->db->save_queries = TRUE;
$str = $this->db->last_query();
echo $str;

Cheers.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.