问题
$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