如果未关闭MySQL数据库会怎样

如果未关闭MySQL数据库会怎样

本文介绍了如果未关闭MySQL数据库会怎样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果未关闭MySQL数据库怎么办?我们如何知道它是否正确关闭?

What happens if MySQL database is not closed? How do we know if it is closed properly?

我确实有一个页面,页面上有11个表..所以我要做的是在脚本开始之前在页面顶部打开数据库,然后关闭脚本(PHP)结束的地方...

I do have a page which has 11 tables on a page..so what I did is I open database on top of page before script starts and close where the scripts(PHP) ends...

结尾是mysql_close($ db); ...足够公平还是我只需要给出mysql_close();

the ending is mysql_close($db);...is this fair enough or do I need to give only mysql_close();

推荐答案

我不确定所有服务器平台上的所有PHP/Mysql版本是否都表现相同.对于与数据库的tcp连接-除非调用mysql_close($ db),否则您将有一个悬空的tcp连接坐在那里,等待脚本结束后等待半分钟.然后它会自行消失.

I can't say for sure if all PHP/Mysql versions on all server platforms behave the same way. For tcp connections to the database - unless you call mysql_close($db), you'll have a dangling tcp connection just sitting there waiting to be used for half a minute after the script ends. Then it'll just go away on its own.

我不能说这是PHP的垃圾回收需要花费整整30秒才能完成,还是一旦您调用connect,tcp连接是否设置为在30秒后自行失效.

I can't say if this is PHP's garbage collection taking a full 30 seconds to complete, or if the tcp connection is set to expire after 30 seconds on its own once you call connect.

Mysql_close($ db)会立即终止tcp连接.是的,我想说,在您的脚本中不再需要数据库连接之后,总是立即调用mysql_close($ db).

Mysql_close($db) instantly kills the tcp connection though. So yeah, I'd say always call mysql_close($db) immediately after you no longer need a database connection in your script.

这篇关于如果未关闭MySQL数据库会怎样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 14:54