3

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

Danish
  • 153
  • 1
  • 11

3 Answers3

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.

Danish
  • 153
  • 1
  • 11
0

I want to ask why are printing query like array simply use

$str = $this->db->last_query();
echo $str; 
user7596840
  • 139
  • 13
0

Create a helper function and use it anywhere in your project:

function lq(){  echo $this->db->last_query(); die; }

and call to controller and model like:

lq();
סטנלי גרונן
  • 2,740
  • 21
  • 43
  • 62