本文介绍了PDO:无效的参数编号:混合的命名和位置参数-注释中的问号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
今天,我遇到了一个以前从未见过的错误(在PDO中),但是当您考虑该错误时,这一点就显而易见了.
Today I encountered a bug (in PDO) I never saw before, but is kinda obvious when you think about it.
我收到以下错误:Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters
我使用的查询类似于以下内容:
The query I was using was similar to the following:
SELECT
x
FROM
y
WHERE
-- CHECKING IF X = ? --
x = :y
AND
1 = 2
很明显,我有更多的参数和更长的查询.
Obviously I had more parameters and a longer query.
为什么会给我这个错误?
Why does it give me this error?
推荐答案
解决方案很明显:PDO不理会注释,而是看到?作为位置参数.删除?在您的评论中解决了这个问题.
The solution is obvious: PDO disregards comments as such and sees the ? as a positional parameter. Removing the ? in your comment solves this problem.
这篇关于PDO:无效的参数编号:混合的命名和位置参数-注释中的问号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!