The answer is "it depends".
In most situations, database connections are a limited resource, just like disk space or bandwidth, etc. For example, if you had a maximum limit of 100 database connections, and many clients trying to connect at the same time, you would want each client to get its data then disconnect as soon as possible, in order to not block other clients. This would be like an ATM machine checking an account balance at a bank.
On the other hand, if you had a server connected to the database, and lots of clients making similar requests at the same time, it might be better for the server to establish a single, persistent connection to the database, and cache commonly accessed data to avoid redundant queries.
This would be like a web site where users read book reviews, for example.
| [reply] |
| [reply] |
| [reply] |
| [reply] |
I think it is better to just have a single connection if possible. So that if anything goes wrong, you can just terminate a single process in the database.
Imagine if you have multiple connection and something goes wrong then you can end up saturating your database with your script and making it unusable.
| [reply] |