Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter Active Record: Debugging without running SQL

I'm fairly new to Code Igniter, and I'm using Active Record for all the queries in a new project.

Is there a way to output the SQL statement without actually running it.

The function i've created has quite a few statements in it, selects, deletes and updates, and I want to make sure they are correct before running them in a test environment as they have a lot of Ifs and cases around them to build up the queries.

So in short, I just want it to echo the statement, but not run it.

Thanks in advance! :)

like image 699
David 'davethegeek' Dingvean Avatar asked Sep 23 '26 22:09

David 'davethegeek' Dingvean


2 Answers

Take a look at the insert_string() and update_string() methods listed in the Database Query Helper section of the user guide.

For select you'll need to run $this->db->last_query() after you've run the command, but SELECT is non-destructive so who cares.

like image 194
Phil Sturgeon Avatar answered Sep 26 '26 10:09

Phil Sturgeon


Take a look at this answer of mine.
How can I rewrite this SQL into CodeIgniter's Active Records?

In this if you use $this->db->_compile_select() and then echo it it will display the query without running.

like image 35
Muhammad Raheel Avatar answered Sep 26 '26 10:09

Muhammad Raheel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!