CodeIgniter Forums
newbie active record question: show me the SQL! - 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: newbie active record question: show me the SQL! (/showthread.php?tid=7247)



newbie active record question: show me the SQL! - El Forum - 03-31-2008

[eluser]andjules[/eluser]
I've implemented a search function, and built the query using a few of the active record commands. I'm getting results, but clearly not the right ones...
SO, I want to debug
BUT I can't find documentation on how to get CI to show me the final SQL used by active record!


newbie active record question: show me the SQL! - El Forum - 03-31-2008

[eluser]ontguy[/eluser]
The application profiler will show the sql used. Just add $this->output->enable_profiler(TRUE); to a controller function; http://ellislab.com/codeigniter/user-guide/general/profiling.html


newbie active record question: show me the SQL! - El Forum - 04-01-2008

[eluser]Unknown[/eluser]
or ...

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

Returns the last query that was run (the query string, not the result). Example:
Code:
$str = $this->db->last_query();
Code:
echo $str;

// Produces: SELECT * FROM sometable....

ripped from the user_guide