Can't get result from $this->db->last_query(); codeigniter

activerecord, codeigniter, join, php

Solution

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.

Problem

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

Original source