Welcome Guest, Not a member yet? Register   Sign In
Query Binding Not Replacing '?'
#1

[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?
#2

[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.
#3

[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.
#4

[eluser]hightower[/eluser]
Thanks!

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

Once again, thanks




Theme © iAndrew 2016 - Forum software by © MyBB