gpt4 book ai didi

php - bindParam和bindValue有什么区别?

转载 作者:行者123 更新时间:2023-11-29 22:55:56 26 4
gpt4 key购买 nike

最佳答案

来自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/28725286/

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