我有以下查询:
SELECT case when card_type='A' then name else CONCAT_WS(' ',firstname,lastname) end
as cname ,cardid,card_type,isDeck,userid_from,status,cards.gibid,message ,userid_to,description,tagline,gibs.preview_thumb
,case when userid_from=userid_to then 'my card ' else 'other 'end as owner
FROM cards LEFT JOIN gibs ON gibs.gibid=cards.gibid
left join users on users.userid=cards.userid_from
WHERE userid_to=? and cards.deleted='N' and (case when card_type='A' then name else CONCAT_WS(' ',firstname,lastname) end) like '%?%'
order by status,card_type desc,owner,cname,isDeck desc
和执行函数传递的数组是:
Array
(
[0] => 1
[1] => rahul
)
它给了我错误..
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in /var/www/ryapi/Db.php on line 176
Fatal error: Uncaught exception 'PDOException' with message 'Database error [HY093]: , driver error code is ' in /var/www/ryapi/Db.php:179
Stack trace:
#0 /var/www/ryapi/Db.php(93): Db::_query('SELECT case whe...', Array)
#1 /var/www/ryapi/card.php(152): Db::getResult('SELECT case whe...', Array)
#2 /var/www/ryapi/index.php(103): Card->getcardlist('1', '', 'rahul')
#3 {main}
thrown in /var/www/ryapi/Db.php on line 179
为什么会出现此错误,请建议。
答案 0 :(得分:5)
CONCAT_WS(' ',firstname,lastname) end) like '%?%'
在这里,'%?%'不是pdo param。 你应该做到:
CONCAT_WS(' ',firstname,lastname) end) like ?
然后绑定:
Array
(
[0] => 1
[1] => '%rahul%'
)
答案 1 :(得分:2)
这很可能是你的问题:
CONCAT_WS(' ',firstname,lastname) end) like '%?%'
绑定参数不起作用,需要将其更改为
CONCAT_WS(' ',firstname,lastname) end) like ?
并使用通配符扩展您传入的值。
答案 2 :(得分:0)
这是一个可以在PHP中修复的简单错误。你还没有包含PHP,所以我们无法分辨。
你需要调整数量吗?你的pdo->准备陈述中的符号。