bindParam 和 bindValue 有什么区别? [英] What is the difference between bindParam and bindValue?
本文介绍了bindParam 和 bindValue 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
PDOStatement::bindParam()
和有什么区别代码> 和 PDOStatement::bindValue()
?
What is the difference between PDOStatement::bindParam()
and 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.
调用 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屋!
查看全文