gpt4 book ai didi

php - bindParam 和 bindValue 有什么区别?

转载 作者:行者123 更新时间:2023-11-30 22:31:47 27 4
gpt4 key购买 nike

PDOStatement::bindParam() 之间有什么区别?和 PDOStatement::bindValue()

最佳答案

来自 the manual entry for PDOStatement::bindParam :

[With bindParam] Unlike PDOStatement::bindValue(), the variable is bound as a reference and will only be evaluated at the time that PDOStatement::execute() is called.

所以,例如:

$sex = 'male';
$s = $dbh->prepare('SELECT name FROM students WHERE sex = :sex');
$s->bindParam(':sex', $sex); // use bindParam to bind the variable
$sex = 'female';
$s->execute(); // executed with WHERE sex = 'female'

$sex = 'male';
$s = $dbh->prepare('SELECT name FROM students WHERE sex = :sex');
$s->bindValue(':sex', $sex); // use bindValue to bind the variable's value
$sex = 'female';
$s->execute(); // executed with WHERE sex = 'male'

关于php - bindParam 和 bindValue 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33700636/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com