php中bindValue 和 bindParam 的区别
2010-04-21 11:01
447 查看
// 注意:
// bindParam是绑定一个PHP变量到一个SQL参数.是引用方式传递
// 所以你可以改变变量值,再执行.就赋给SQL语句不同的值
// 注意与bindValue的区别
try {
$sql = 'UPDATE `pdo` set `user` = :user, `email` = :email WHERE `id` = :id';
$pre = $dbh->prepare($sql);
// 此处bindParam.执行一次更改id=2,执行一次更改id=3.结果不一样
$user = "ncat2";
$email = "ncat2@gmail.com";
$id = 2;
$pre->bindParam(':user', $user, PDO::PARAM_STR);
$pre->bindParam(':email', $email, PDO::PARAM_STR);
$pre->bindParam(':id', $id, PDO::PARAM_INT);
$pre->execute();$user = "ncat3";
$email = "ncat3@gmail.com";
$id = 3;
$pre->execute();
unset($user, $email, $id);
// 此处bindValue. 执行两次id=4的SQL$user = "ncat4";
$email = "ncat4@gmail.com";
$id = 4;
$pre->bindValue(':user', $user, PDO::PARAM_STR);
$pre->bindValue(':email', $email, PDO::PARAM_STR);
$pre->bindValue(':id', $id, PDO::PARAM_INT);
$pre->execute();
$user = "ncat5";
$email = "ncat5@gmail.com";
$id = 5;$pre->execute();
} catch (PDOException $e)
{var_dump($e);}
// bindParam是绑定一个PHP变量到一个SQL参数.是引用方式传递
// 所以你可以改变变量值,再执行.就赋给SQL语句不同的值
// 注意与bindValue的区别
try {
$sql = 'UPDATE `pdo` set `user` = :user, `email` = :email WHERE `id` = :id';
$pre = $dbh->prepare($sql);
// 此处bindParam.执行一次更改id=2,执行一次更改id=3.结果不一样
$user = "ncat2";
$email = "ncat2@gmail.com";
$id = 2;
$pre->bindParam(':user', $user, PDO::PARAM_STR);
$pre->bindParam(':email', $email, PDO::PARAM_STR);
$pre->bindParam(':id', $id, PDO::PARAM_INT);
$pre->execute();$user = "ncat3";
$email = "ncat3@gmail.com";
$id = 3;
$pre->execute();
unset($user, $email, $id);
// 此处bindValue. 执行两次id=4的SQL$user = "ncat4";
$email = "ncat4@gmail.com";
$id = 4;
$pre->bindValue(':user', $user, PDO::PARAM_STR);
$pre->bindValue(':email', $email, PDO::PARAM_STR);
$pre->bindValue(':id', $id, PDO::PARAM_INT);
$pre->execute();
$user = "ncat5";
$email = "ncat5@gmail.com";
$id = 5;$pre->execute();
} catch (PDOException $e)
{var_dump($e);}
相关文章推荐
- php的PDO类中bindValue和bindParam的区别
- php的PDO类中bindValue和bindParam的区别
- php pdo中bindParam() 和 bindValue()方法的区别
- php pdo中PDOStatement 类的bindParam和bindValue方法的区别
- php的PDO类中bindValue和bindParam的区别
- PHP 5.3.6及以前版本的PDO的bindParam,bindValue潜在的安全隐患
- bindColumn、bindParam与bindValue的区别
- pdo中使用bindParam和bindValue的区别
- mysql pdo bindValue和bindparam的区别
- bindParam和bindValue的区别以及在Yii2中的使用详解
- bindParam和bindValue的区别以及在Yii2中的使用
- PHP PDOStatement对象bindpram()、bindvalue()和bindcolumn之间的区别
- bindColumn、bindParam与bindValue的区别
- PHP 5.3.6及以前版本的PDO的bindParam,bindValue潜在的安全隐患
- PHP PDOStatement对象bindpram()、bindvalue()和bindcolumn之间的区别
- PDO的bindParam与bindValue的区别
- PHP扩展PDO MySQL之PDOStatement::bindParam vs bindValue
- pdo中bindParam()与bindValue的区别
- @PathVariable,@RequestParam, @RequestBody,@ModelAttribute,@RequestHeader,@CookieValue的区别
- php pdo bindParam 二三事