3

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! :)

2 Answers2

4

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.

Phil Sturgeon
  • 30,637
  • 12
  • 78
  • 117
1

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.

Community
  • 1
  • 1
Muhammad Raheel
  • 19,823
  • 7
  • 67
  • 103