pg_query_params返回错误:绑定消息提供2个参数,但是准备好的语句“”需要1 [英] pg_query_params return error: bind message supplies 2 parameters, but prepared statement "" requires 1

查看:576
本文介绍了pg_query_params返回错误:绑定消息提供2个参数,但是准备好的语句“”需要1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$Query = pg_query_params($db, 'SELECT username FROM users WHERE id = $1 AND password=(crypt(\'$2\',password)) LIMIT 1', array(33,'thepassword'));

绑定消息提供2个参数,但准备好的语句需要1个

"bind message supplies 2 parameters, but prepared statement "" requires 1"

问题似乎在'$ 2'参数周围,heredoc字符串不起作用。

The problem seem around the '$2' parameter, heredoc string doesnt works.

建议?

推荐答案

在SQL中,单引号用于字符串文字。这意味着:

Single quotes are used in SQL for string literals. That means that this:

'$2'

只是一个包含字符 $ 2 的字符串一个占位符。如果需要占位符,则需要省略引号:

is just a string that contains the characters $ and 2 rather than a placeholder. If you want a placeholder, you need to leave out the quotes:

$Query = pg_query_params($db, '...password=(crypt($2,password))...', array(33,'thepassword'));

这为您提供占位符,而不是字符串文字。

That gives you the placeholder rather than the string literal.

这篇关于pg_query_params返回错误:绑定消息提供2个参数,但是准备好的语句“”需要1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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