标签:tac 变量 绑定 nts markdown hat prepare student 区别
PDOStatement::bindParam 与 PDOStatement::bindValue()不同, 变量被以引用方式绑定到点位符上而且仅仅当调用PDOStatement::execute()时才会去计算具体被绑定变量在PDOStatement::execute()被调用时的值.
So, for example:
<?php
$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(); // 将执行 WHERE sex = ‘female‘
or
<?php
$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(); // 将执行 WHERE sex = ‘male‘
标签:tac 变量 绑定 nts markdown hat prepare student 区别
原文地址:http://www.cnblogs.com/hongjh/p/7851590.html