PHP and MySQLi close()

无人久伴 提交于 2019-12-31 08:34:55

问题


I am new to MySQL and PHP and am attempting to make my own CMS to help make managing my websites easier. Can someone explain mysqli's close() function?

  1. Is it necessary?
  2. What exactly does it do?
  3. I heard that after PHP runs its script that it closes the connection, is that true?
  4. Lastly, is there a security issue when not closing your connection to the database?

回答1:


Is it necessary?

No, PHP will end your connection after it finishes running.

What exactly does it do?

The reverse of mysqli_connect() -- it closes the active DB connection.

I heard that after PHP runs its script that it closes the connection, is that true?

Yes, see the answer to "Is it necessary?"

Lastly, is there a security issue when not closing your connection to the database?

Nope, no security issue. The connection can't be hijacked by an outsider or anything like that.

However, since the number of total connections available is limited, freeing the resource the second you're done with it is considered polite to close it when you're done. This is likely why you've been told to close it when you're done.




回答2:


You need to close the Mysql session when you manual set variables @@session or non-defined (set to @@session).
for example

 $mysqli->query("SET @uuid=UUID()");

https://dev.mysql.com/doc/refman/5.1/en/set-statement.html



来源:https://stackoverflow.com/questions/2876412/php-and-mysqli-close

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!