postgresql pg_query_params 返回错误:绑定消息提供 2 个参数,但准备好的语句“”需要 1
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26209479/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
pg_query_params return error: bind message supplies 2 parameters, but prepared statement "" requires 1
提问by DPZ
$Query = pg_query_params($db, 'SELECT username FROM users WHERE id = AND password=(crypt(\'\',password)) LIMIT 1', array(33,'thepassword'));
"bind message supplies 2 parameters, but prepared statement "" requires 1"
“绑定消息提供 2 个参数,但准备好的语句”“需要 1”
The problem seem around the '$2' parameter, heredoc string doesnt works.
问题似乎与 '$2' 参数有关,heredoc 字符串不起作用。
Suggestions ?
建议?
回答by mu is too short
Single quotes are used in SQL for string literals. That means that this:
单引号在 SQL 中用于字符串文字。这意味着:
''
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:
仅仅是一个包含字符的字符串$
和2
,而不是一个占位符。如果你想要一个占位符,你需要省略引号:
$Query = pg_query_params($db, '...password=(crypt(,password))...', array(33,'thepassword'));
That gives you the placeholder rather than the string literal.
这为您提供了占位符而不是字符串文字。