Pg_query_params return error: bind message supplies 2 parameters, but prepared statement "" requires 1

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

"associate messages with deliveries 2 parameters, but prepared statement" "requires 1"

The problem arises around the $ 2 parameter, the heredoc line does not work.

Suggestions?

+8
php postgresql prepared-statement
source share
1 answer

Single quotes are used in SQL for string literals. This means that it is:

 '$2' 

is just a string containing the characters $ and 2 , not a placeholder. If you want to fill out, you need to leave a quote:

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

This gives you a placeholder, not a string literal.

+10
source share

All Articles