Reputation: 1335
Suppose i have code like this:
SELECT * FROM tbl WHERE ? ORDER BY id desc limit 1
$query = $this->prepare($q);
i need to put the following conditions to the where condition:
(id=1 and age=20) or (x=50 and y='yes')
But $query->execute(array("(id=1 and age=20) or (x=50 and y='yes')"));
is not fetching any vaues.
How can I put prepared statements for 'where' clause condition. Kindly help me to fix it.
Upvotes: 3
Views: 1931
Reputation: 182
input parameters will be values not expression.. you can try the following..
SELECT * FROM tbl WHERE (id=? and age=?) or (x=? and y=?) ORDER BY id desc limit 1
$query = $this->prepare($q);
$query->execute(array(1, 20, 50, 'yes'));
Upvotes: 3