CodeIgniter Forums
Query Binding Not Replacing '?' - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Query Binding Not Replacing '?' (/thread-21806.html)



Query Binding Not Replacing '?' - El Forum - 08-21-2009

[eluser]hightower[/eluser]
I have the following code:

Code:
$sql = "SELECT articles.body, articles.user_id, users.username FROM articles, users WHERE ? = 1 AND articles.user_id = users.user_id ORDER BY ?";

$query = $this->db->query($sql, array('item1', 'item2'));
echo $sql;

The output from the echo however is:

Code:
SELECT articles.body, articles.user_id, users.username FROM articles, users WHERE ? = 1 AND articles.user_id = users.user_id ORDER BY ?

It's not replacing the question marks. I've checked the code, and it looks ok, and I've searched the forums/userguide but can't find anything that might help.

Anybody got any ideas?


Query Binding Not Replacing '?' - El Forum - 08-21-2009

[eluser]davidbehler[/eluser]
You are echoing the $sql variable which only holds your original query with the question marks.
Try this
Code:
echo $this->db->last_query();

Now you should get the query with replaces question marks.


Query Binding Not Replacing '?' - El Forum - 08-21-2009

[eluser]sl3dg3hamm3r[/eluser]
the variable $sql will stay as it is. your code looks fine, you just echoing the wrong (unchanged) stuff. $query should contain the result-set.


Query Binding Not Replacing '?' - El Forum - 08-21-2009

[eluser]hightower[/eluser]
Thanks!

Bit of a school boy error there, but the extra set of eyes is always an advantage.

Once again, thanks