pg_query_params return error: bind message supplies 2 parameters, but prepared statement “” requires 1

▼魔方 西西 提交于 2019-12-06 20:18:51

问题


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

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

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

Suggestions ?


回答1:


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

'$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.



来源:https://stackoverflow.com/questions/26209479/pg-query-params-return-error-bind-message-supplies-2-parameters-but-prepared-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!