我的 PDO 执行函数出错
我有以下查询:
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
为什么会出现此错误,请提出建议。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这里,'%?%' 不是 pdo 参数。
你应该这样做:
然后绑定:
Here, '%?%' is not a pdo param.
You should make it:
Then bind:
这很可能是您的问题:
绑定参数不能以这种方式工作,您需要将其更改为
并扩展使用通配符传入的值。
This is most likely your problem:
Binding parameters does not work that way, you need to change it to
and extend the value you're passing in with the wildcards.
这是一个简单的错误,可以在 PHP 中修复。您还没有包含 PHP,所以我们无法判断。
您需要调整 的数量? pdo->prepare 语句中的符号。
This is a simple error that can be fixed in your PHP. You have not included the PHP, so we can't tell.
You need to adjust the number of ? symbols in your pdo->prepare statement.