Why do we have to close the MySQL database after a query command?

后端 未结 2 656
悲哀的现实
悲哀的现实 2021-01-06 07:11

I\'m starter.

I want to know what will happen if we don\'t close the MySQL connection.

1- Is it possible to open more than one database if we don\'t close th

相关标签:
2条回答
  • 2021-01-06 07:26
    1. Yes, you can have multiple database connections. You are not opening a database, you are opening a database connection. The database is 'open' (i.e. running) all of the time, generally speaking, whether you are connected to it or not.
    2. Depends... if you only have one open connection on a page, then you don't need to close it because it will automatically close when PHP is done. If you have many, then you could potentially make the database server slower, or make the database server run out of available connections (it can only have a certain number of connections open at the same time). That said, most modern database servers can handle hundreds of concurrent connections.
    3. Optional, but recommended. It's not a big deal for small-medium projects (i.e. if you have less than 100 concurrent visitors at any given time, you probably won't have any issues regardless). Since you have many thousand visitors per minute, you should actively close the database connection as soon as you are done with it, to free it up as soon as possible.
    0 讨论(0)
  • 2021-01-06 07:27

    Once you connect to the database it is not necessary to close. As non-persistent connection automatically closed at the end of script execution.

    Follow this for more information

    0 讨论(0)
提交回复
热议问题