假设我有这样的代码:
SELECT * FROM tbl WHERE ? ORDER BY id desc limit 1
$query = $this->prepare($q);
我需要将以下条件放到where条件中:
(id=1 and age=20) or (x=50 and y='yes')
但是 $query->execute(array("(id=1 and age=20) or (x=50 and y='yes')"));
没有获取任何值.
如何为 'where' 子句 条件放置准备好的语句。请帮助我修复它。
最佳答案
输入参数将是值而不是表达式..你可以尝试以下..
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'));
关于PHP PDO 为 where 子句准备语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16259364/