老师,bindParam和bindValue的区别是前者需要在每次执行的时候都需要绑定,但是后者是只要在值不变的前提下,只绑定一次就可以重复使用execute么?
嗯 是这样的 所以需要使用可变变量的形式
^-^...
嗯嗯 对的
^-^...
@胖子啊 ,同感,bindvalue需要在每次执行的时候都绑定才行。
$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'<p>
KING 我觉得他说反了吧
区别是bindvalue需要在每次执行的时候都需要绑定,但两者是只要在值不变的前提下,都只绑定一次就可以重复使用execute