views:

93

answers:

2

for example, i want to convert this;

$this->db->get('table');

to this;

'SELECT * FROM table'

is there any function for this? i searched on the user guide of CI but didnt find any solution.

+3  A: 

Try

echo $this->db->last_query();

after you run your Active Record Query and it'll spit out the raw SQL it ran for you. I use it often.

sitesbyjoe
thanks for your answer!! that was what im lookin for.
WhoSayIn
+3  A: 

You can also use $this->db->_compile_select() , difference between _compile_select() and last_query() is that _compile_select() gives the query string generated even if you dont run the query agaisnt the database.

Sandy
thanks for your answer too, good to know that we can see the SQL code before we getting results.
WhoSayIn
Thanks a lot, that function is really useful!
Rocket
I just realized that if you use `_compile_select()`, that you have to use `$this->db->_reset_select();` after executing the query. If you don't, CodeIgniter won't clear the query, and all queries onward won't work.
Rocket