Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Develop #612

Closed
wants to merge 2 commits into from

5 participants

@nicholasnet

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.

@ericbarnes

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

@nicholasnet

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 http://framework.zend.com/manual/en/zend.db.select.html#zend.db.select.execute.tostring.

@saintnicster

https://github.com/EllisLab/CodeIgniter/blob/develop/system/database/DB_driver.php#L679

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

@bubbafoley

this has already been added

#307
12e93fe

@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
View
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.