什么时候应该对 PDO 语句使用 closeCursor()? [英] When should I use closeCursor() for PDO statements?

查看:11
本文介绍了什么时候应该对 PDO 语句使用 closeCursor()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于 closeCursor() 的 PHP 文档说它

The PHP documentation on closeCursor() says that it

释放与服务器的连接,以便可以发出其他 SQL 语句,但使该语句处于可以再次执行的状态.

frees up the connection to the server so that other SQL statements may be issued, but leaves the statement in a state that enables it to be executed again.

当我使用该命令时,它是否存在于我的查询语句之间似乎并不重要,我开始怀疑我是否需要它.

When I have used the command though it doesn't seem to matter if it is there or not in between my query statements, and I am beginning to wonder if I need it at all.

将它用于不返回数据的数据库调用与返回数据的数据库调用是否不同?

Is it different to use it for database calls that don't return data vs. those that do?

推荐答案

这取决于所使用的驱动程序.我认为对于 mysql,这只会清除语句的结果.调用 closeCursor() 后,您不能再调用 fetch().但是,再次执行该语句应该不是问题.尝试查看 mysql_free_result(),它做了类似的事情.

This depends on the driver used. I think for mysql this will do nothing else than clear the result of the statement. After calling closeCursor() you cannot call fetch() anymore. However executing the statement again should not be a problem. Try to look at mysql_free_result(), it does a similar thing.

这篇关于什么时候应该对 PDO 语句使用 closeCursor()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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