What is the difference between bindParam and bindValue?

后端 未结 7 1207
一向
一向 2020-11-22 00:23

What is the difference between PDOStatement::bindParam() and PDOStatement::bindValue()?

7条回答
  •  有刺的猬
    2020-11-22 01:22

    For the most common purpose, you should use bindValue.

    bindParam has two tricky or unexpected behaviors:

    • bindParam(':foo', 4, PDO::PARAM_INT) does not work, as it requires passing a variable (as reference).
    • bindParam(':foo', $value, PDO::PARAM_INT) will change $value to string after running execute(). This, of course, can lead to subtle bugs that might be difficult to catch.

    Source: http://php.net/manual/en/pdostatement.bindparam.php#94711

提交回复
热议问题