Does query execution happen at the get_where()
clause of the following codeigniter active record statement?
$this->db->select('*');
$q = $this->db->get_where('Contacts', array('id' => $contact_id));
$sql = $this->db->last_query();
Or does it happens once you call the result_array()
?
And is $this->db->last_query();
a reliable way in getting the query string.
The query execution happens on all get methods like
While last_query contains the last query which was run
If you want to get query string without execution you will have to do this. Go to system/database/DB_active_rec.php Remove public or protected keyword from these functions
Now you can write query and get it in a variable
Now reset query so if you want to write another query the object will be cleared.
And the thing is done. Cheers!!! Note : While using this way you must use
instead of
which runs the query.
Take a look at this example