duanboshe0001 2013-11-07 12:34
浏览 28
已采纳

在PDO查询中再次使用相同的变量

I'm using PDO prepared statement. Here in the code i use variable res for first prepare statement & operations.

$res=$db->prepare("//code//");
$res->execute($array);
$count=$res->rowCount();

$res=$db->prepare("//code//");
$res->execute($array);
$res->fetch();

Will it create problems if i use reuse the variable for another prepared statement? Is it a wrong practice and should i use another variable for other statement?

  • 写回答

1条回答 默认 最新

  • duanlu7223 2013-11-07 12:37
    关注

    If you're done with that variable, I think you can safely reuse it (I would do it), but some code conventions try to avoid this kind of behaviour.

    See for example this other question: is it acceptable to recycle or reuse variables?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部