CodeIgniter Forums
Seeing query before submitting - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Seeing query before submitting (/thread-31318.html)



Seeing query before submitting - El Forum - 06-14-2010

[eluser]Unknown[/eluser]
This may be a newbie question, but something I can't find in the docs very easily:

Is there a way to see a query string that's built before actually running the query? I know last_query shows you what was run, but for debugging, I'd like to see it without actually submitting it.

$data = array(
'myfield1' => $EmployeeNo,
'myfield2' => date("Y-m-d")
);

$this->db->where('recordno', $RecordNumber);
$this->db->update('propertytable', $data);

This will actually execute the query -- how do I just get a string of what the query will look like to confirm it's being built correctly with my data?


Seeing query before submitting - El Forum - 06-14-2010

[eluser]bretticus[/eluser]
The following code works for SELECT statements. Not sure on an UPDATE so your mileage may vary. Feel free to try it and post if it works:

Code:
// get compiled select statement
$compiled_query = $this->db->_compile_select();
echo $compiled_query;

EDIT...Problem may be that you need to call it before calling update. Hmmm????

On second thought, call it before update(). At least you'll get a SELECT version that will show what goes in your WHERE clause.