PDO-> bindParam,PDO-> bindValue和PDO-> closeCursor [英] PDO->bindParam, PDO->bindValue and PDO->closeCursor

查看:113
本文介绍了PDO-> bindParam,PDO-> bindValue和PDO-> closeCursor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我一直在使用PDO->bindParam,但是在阅读手册时,我发现PDO->bindValue按值传递的位置与PDO->bindParam通过引用传递的位置有关,这是唯一的区别吗?

So far I have been using PDO->bindParam however while reading the manual I found PDO->bindValue from what I can tell PDO->bindValue passes by value where as PDO->bindParam passes by reference, is this the only difference?

$modThread = db()->prepare("UPDATE `threads` SET `modtime` = UNIX_TIMESTAMP( ) WHERE `threadid` =:id LIMIT 1");

while(something)
{
        $modThread->bindParam(':id', $thread);
        $modThread->execute();
//*******************HERE********************//
}

再次阅读我发现的手册时:PDO->closeCursor我应该将其放置在标记的地方吗?它是可选的/自动调用的吗?似乎只有某些驱动程序需要它.在不需要/不支持它的驱动程序上调用它会导致错误吗? MySQL怎么样?

Again while reading the manual I found: PDO->closeCursor should I place it where marked? Is it optional/automatically called? Seems only certain drivers need it. Will calling it on a driver that doesn't need/support it cause errors? How about MySQL?

推荐答案

这里的重复出现" bindParam()并不是必须的:

The 'recurring' bindParam() here is not really necessary:

$thread = 0;
$modThread->bindParam(':id', $thread);

while($thread < 20)
{
    $thread++;
    $modThread->execute(); //executing with the new value, which you couldn't do with bindValue
}

在没有结果集时(即仅使用SELECT或过程将结果返回),您不需要closeCursor(),但是通常我已经在上一条语句/行中的某处完成了fetchAll.

You don't need a closeCursor() when there is no resultset (i.e, only with SELECT s or procedures giving results back) , but usually I've already done a fetchAll somewhere in a previous statement / row.

这篇关于PDO-> bindParam,PDO-> bindValue和PDO-> closeCursor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆