CodeIgniter Forums
question about active records / db - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: question about active records / db (/showthread.php?tid=3593)



question about active records / db - El Forum - 10-12-2007

[eluser]Unknown[/eluser]
Hi.

I want to know how do I get the sql string what was generated by active records class.
For example, I have this code:
$this->db->select('*');
$this->db->where('id',3);
$this->db->where('name','test');
$this->db->from('my_table');

$query=$this->db->get();

The class generates something like
"select * from my_table where id=3 and name='test'"

How do I get this sql string ?


Thanks


question about active records / db - El Forum - 10-12-2007

[eluser]alexsancho[/eluser]
You've got two options,

- Enabling profiler
Code:
$this->output->enable_profiler = TRUE;

- Using active record last_query

Code:
$this->db->last_query()


hopes this helps


question about active records / db - El Forum - 10-12-2007

[eluser]Alex007[/eluser]
Both of these methods will work IF the query has been run.

If you want to compile the SQL string without running it, try this:
Code:
$sql = $this->db->_compile_select();