【问题标题】:pg_query_params return error: bind message supplies 2 parameters, but prepared statement "" requires 1pg_query_params 返回错误:绑定消息提供 2 个参数,但准备好的语句“”需要 1 个
【发布时间】:2014-11-30 07:32:31
【问题描述】:
$Query = pg_query_params($db, 'SELECT username FROM users WHERE id = $1 AND password=(crypt(\'$2\',password)) LIMIT 1', array(33,'thepassword'));

"绑定消息提供2个参数,但prepared statement""需要1个"

问题似乎与“$2”参数有关,heredoc 字符串不起作用。

建议?

【问题讨论】:

    标签: php postgresql prepared-statement


    【解决方案1】:

    单引号在 SQL 中用于字符串文字。这意味着:

    '$2'
    

    只是一个包含字符$2 的字符串,而不是占位符。如果你想要一个占位符,你需要省略引号:

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

    这给了你占位符而不是字符串文字。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-23
      • 2017-05-14
      • 2013-08-09
      • 1970-01-01
      • 2021-08-01
      • 2020-06-24
      • 1970-01-01
      相关资源
      最近更新 更多