码迷,mamicode.com
首页 > 其他好文 > 详细

PDO的bindParam与bindValue的区别

时间:2017-11-17 16:16:39      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:tac   变量   绑定   nts   markdown   hat   prepare   student   区别   

转自:https://stackoverflow.com/questions/1179874/what-is-the-difference-between-bindparam-and-bindvalue#answer-5077108

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‘

PDO的bindParam与bindValue的区别

标签:tac   变量   绑定   nts   markdown   hat   prepare   student   区别   

原文地址:http://www.cnblogs.com/hongjh/p/7851590.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!