准备好的查询“持续”多久? 在服务器端?
我只是想知道准备好的查询是如何工作的。 我正在使用 PHP 和 MySQL。
我知道准备好的查询会编译查询,然后重复使用只需更改参数,因此节省了时间。 但是编译后的查询会产生多长时间的效果呢? 什么时候必须重新评估? 只要PHP脚本运行就可以吗? 或者只要存在与数据库的连接就可以吗? 那么,持久连接会对它有什么影响吗?
I was just wondering how prepared queries work. I am using PHP and MySQL.
I know that prepared queries compile the query and then repeated uses only have to change the parameters, so it saves time. But how long does that compiled query have an effect? At which point does it have to be reevaluated? Is it just as long as the PHP script is running? Or is it as long as the connection to the database is present? In that case, would a persistent connection have any effect on it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ryeguy,它们会持续整个连接时间。 根据 MySQL 手册:
如果您没有使用持久连接,那么当您的脚本完成执行时(或者您显式地释放它,或关闭连接),这将被释放。 如果使用持久连接,那么它将在使用相同持久连接的多个 PHP 会话中持久存在。
ryeguy, they last for the length of the connection. Per the MySQL manual:
If you are not using persistent connections, then this will be deallocated when your script finishes executing (or you explicitly deallocate it, or close the connection). If using persistent connections, then it will persist across multiple PHP sessions using the same persistent connection.
据我所知,只要存储它的变量在范围内,准备好的查询就会“持续”。 我想可能有一些方法可以缓存准备好的查询以供以后使用,但我不知道 MySQL 是否这样做。
As far as I know, a prepared query will only "last" for as long as the variable storing it is within scope. I suppose there could be some ways to cache prepared queries for later use, but I don't know if MySQL does this.
hobodave 是对的,它们的持续时间与创建它们的会话一样长。
还有另一件事需要考虑:
hobodave is right, they just last as long as the session they were created in.
There's one other thing to consider, too: