PDOStatement::bindParam()和之间有什么区别PDOStatement::bindValue()?
PDOStatement::bindParam()
PDOStatement::bindValue()
答案在文档中bindParam:
bindParam
与PDOStatement :: bindValue()不同,该变量被绑定为引用,并且仅在调用PDOStatement :: execute()时进行评估。
和 execute
execute
调用PDOStatement :: bindParam()将PHP变量绑定到参数标记:绑定变量将其值作为输入传递,并接收其关联参数标记的输出值(如果有)
例:
$value = 'foo'; $s = $dbh->prepare('SELECT name FROM bar WHERE baz = :baz'); $s->bindParam(':baz', $value); // use bindParam to bind the variable $value = 'foobarbaz'; $s->execute(); // executed with WHERE baz = 'foobarbaz'
要么
$value = 'foo'; $s = $dbh->prepare('SELECT name FROM bar WHERE baz = :baz'); $s->bindValue(':baz', $value); // use bindValue to bind the variable's value $value = 'foobarbaz'; $s->execute(); // executed with WHERE baz = 'foo'