Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'));

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

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

Suggestions ?

like image 1000
DPZ Avatar asked Oct 06 '14 02:10

DPZ


1 Answers

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.

like image 153
mu is too short Avatar answered Nov 17 '22 20:11

mu is too short