PHP PDO为where子句准备了语句

时间:2020-12-05 12:02:55

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:

我需要将以下条件置于where条件:

(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.

但$ query-> execute(array(“(id = 1 and age = 20)or(x = 50 and y ='yes')”));没有获取任何vaues。如何为'where'子句条件放置预准备语句。请帮我修理一下。

1 个解决方案

#1


1  

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'));

#1


1  

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'));