
` PDOStatement :: bindParam()代码>和 PDOStatement :: ?
bindValue()
答案在[ bindParam < /一个>:
Unlike PDOStatement::bindValue(), the variable is bound as a reference and
will only be evaluated at the time that PDOStatement::execute() is called.
和 execute
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
从[手动输入PDOStatement :: bindParam :
[With
bindParam] UnlikePDOStatement::bindValue(), the variable is bound
as a reference and will only be evaluated at the time thatPDOStatement::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'
未经作者同意,本文严禁转载,违者必究!




近期评论