Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Develop #612

wants to merge 2 commits into from

5 participants


Currently CodeIgniter does not have way to see query built my active record. For example in ZF you can echo out SQL made by Zend Select. So, I wrote similar thing for CI.


CodeIgniter does include $this->db->last_query(); which will show you the query.


As far I know $this->db->last_query(); only shows latest query that was fired. My modification shows query that was prepared by active record before query execution. For more information please visit


That only shows the last executed query. This gives you the potential to view/dump query as you are building it.

Seems like a neat little query, though it'd probably be better if it were renamed to something like current_querry() instead of overriding the __toString() method of the class


this has already been added


@derekjones derekjones closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 0 deletions.
  1. +11 −0 system/database/DB_active_rec.php
11 system/database/DB_active_rec.php
@@ -1851,6 +1851,17 @@ protected function _track_aliases($table)
+ /**
+ * Get Compile SQL
+ * returns compiled SQL
+ * @return string
+ */
+ public function __toString()
+ {
+ $sql = $this->_compile_select();
+ return $sql;
+ }
// --------------------------------------------------------------------
Something went wrong with that request. Please try again.