Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP PDO为where子句准备语句_Php_Mysql_Pdo - Fatal编程技术网

PHP PDO为where子句准备语句

PHP PDO为where子句准备语句,php,mysql,pdo,Php,Mysql,Pdo,假设我有这样的代码: 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(数组((id=1,age=20)或(x=50,y=yes))未获取任何值。 如何将准备好的语句放入“where”子句的条件中。请帮助我修复它。输入参

假设我有这样的代码:

 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(数组((id=1,age=20)或(x=50,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'));

占位符用于值,而不是表达式。