Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.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:绑定变量的数量与令牌的数量不匹配_Php_Pdo - Fatal编程技术网

Php PDO:绑定变量的数量与令牌的数量不匹配

Php PDO:绑定变量的数量与令牌的数量不匹配,php,pdo,Php,Pdo,PHP/SQL代码: $sth = $dbh->prepare("SELECT * FROM `jobs` WHERE `city` = :city AND `district` = :district AND `type` = :type AND ( CONVERT( `id` USING utf8 ) LIKE '% :keyword %' OR CONVERT( `owner` USING utf8 ) LIKE '% :keyword %' OR CONVE

PHP/SQL代码:

$sth = $dbh->prepare("SELECT * 
FROM  `jobs` 
WHERE  `city` = :city
AND  `district` = :district
AND  `type` = :type
AND (
CONVERT(  `id` 
USING utf8 ) LIKE  '% :keyword %'
OR CONVERT(  `owner` 
USING utf8 ) LIKE  '% :keyword %'
OR CONVERT(  `title` 
USING utf8 ) LIKE  '% :keyword %'
OR CONVERT(  `city` 
USING utf8 ) LIKE  '% :keyword %'
OR CONVERT(  `district` 
USING utf8 ) LIKE  '% :keyword %'
OR CONVERT(  `type` 
USING utf8 ) LIKE  '% :keyword %'
OR CONVERT(  `payrate` 
USING utf8 ) LIKE  '% :keyword %'
OR CONVERT(  `hours` 
USING utf8 ) LIKE  '% :keyword %'
OR CONVERT(  `description` 
USING utf8 ) LIKE  '% :keyword %'
)
LIMIT 0 , 30");

$sth->bindParam(':city', $city);
$sth->bindParam(':district', $district);
$sth->bindParam(':type', $type);
$sth->bindParam(':keyword', $keyword);
$sth->execute();
似乎是我的一个标记/变量没有正确“绑定”吗?你知道在哪里/如何改正吗

我猜我需要在某个地方转义一些东西,以便变量正确工作,但是我对PDO和它的布局方式相当陌生


谢谢。

尝试删除
:keyword
周围的引号,并将
%
通配符移动到您的
bindParam
调用中

$sth = $dbh->prepare("SELECT * 
FROM  `jobs` 
WHERE  `city` = :city
AND  `district` = :district
AND  `type` = :type
AND (
CONVERT(  `id` 
USING utf8 ) LIKE  :keyword
OR CONVERT(  `owner` 
USING utf8 ) LIKE  :keyword
OR CONVERT(  `title` 
USING utf8 ) LIKE  :keyword
OR CONVERT(  `city` 
USING utf8 ) LIKE  :keyword
OR CONVERT(  `district` 
USING utf8 ) LIKE  :keyword
OR CONVERT(  `type` 
USING utf8 ) LIKE  :keyword
OR CONVERT(  `payrate` 
USING utf8 ) LIKE  :keyword
OR CONVERT(  `hours` 
USING utf8 ) LIKE  :keyword
OR CONVERT(  `description` 
USING utf8 ) LIKE  :keyword
)
LIMIT 0 , 30");

$sth->bindParam(':city', $city);
$sth->bindParam(':district', $district);
$sth->bindParam(':type', $type);
$sth->bindParam(':keyword', "%$keyword%");
$sth->execute();

当我的一个参数值是
null
var_dump()
您的值:
$city,$district,$keyword
等时,我通常会得到这个结果。我没有意识到null值可能会导致这个问题,看起来两种解决方案都解决了这个问题,谢谢!可能重复的