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


PDO: Number of bound variables does not match the number of tokens

PHP/SQL Code:

$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();