bindParam和bindValue有什么区别? [英] What is the difference between bindParam and bindValue?
本文介绍了bindParam和bindValue有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
PDOStatement::bindParam()
和 PDOStatement::bindValue()
?
推荐答案
答案在 bindParam
:
与PDOStatement :: bindValue()不同,该变量被绑定为引用,并且仅在调用PDOStatement :: execute()时进行评估.
Unlike PDOStatement::bindValue(), the variable is bound as a reference and will only be evaluated at the time that PDOStatement::execute() is called.
和 execute
调用PDOStatement :: bindParam()将PHP变量绑定到参数标记:绑定的变量将其值作为输入传递,并接收其相关参数标记的输出值(如果有)
call PDOStatement::bindParam() to bind PHP variables to the parameter markers: bound variables pass their value as input and receive the output value, if any, of their associated parameter markers
示例:
$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'
这篇关于bindParam和bindValue有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文