老师,bindParam和bindValue的区别是前者需要在每次执行的时候都需要绑定,但是后者是只要在值不变的前提下,只绑定一次就可以重复使用execute么?
5 回答
@胖子啊 ,同感,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'
举报
0/150
提交
取消