Getting raw SQL Queries in CodeIgniter 1.7


Question

I'm trying to debug some code in my first serious CodeIgniter app and I can't seem to find where I can simply get the raw SQL that my ActiveRecord code just generated.

    $where  = 'DAY(`datetime_start`) = '. date('d',$day) .' AND ';
    $where .= 'MONTH(`datetime_start`) = '. date('m',$day) .'';

    $this->db->from('events')->where($where);
    $result = $this->db->get();

Thanks for the help!

1
26
1/18/2013 7:30:54 AM

Accepted Answer

Before the query runs:

$this->db->_compile_select(); 

And after it has run:

$this->db->last_query();
42
7/13/2011 9:27:46 AM

Also, you can put the following in your controller:

$this->output->enable_profiler(TRUE);

You'll get queries and a lot more.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon