PDO无效的参数编号-注释中的参数 [英] PDO Invalid parameter number - parameters in comments

查看:41
本文介绍了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:

我使用的查询类似于以下内容:

The query I was using was similar to the following:

SELECT
    x
FROM
    y
WHERE
    -- CHECKING IF X = :Z --
    x = :y
AND
    1 = 2

很明显,我有更多的参数和更长的查询.

Obviously I had more parameters and a longer query.

为什么会给我这个错误?

Why does it give me this error?

推荐答案

解决方案很明显:PDO不理会注释,而是尝试绑定不存在的变量':Z'.您不能在PDO的注释中使用参数(除非您将其绑定).

The solution is obvious: PDO disregards comments as such and tries to bind the non-existent variable ':Z'. You can't use parameters in comments in PDO (unless you do bind them).

在问号中有一个类似的错误评论.

这篇关于PDO无效的参数编号-注释中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆