When should I open a database connection?
- Should I keep DB connection open?
- What is the best way to handle database connection?
- Should I close DB connection after query?
- Which function is used to open a database connection?
Should I keep DB connection open?
Absolutely it is safe to do this. This is how client-server applications work. If you are using a three-tier application, the application server will keep a pool of connections open anyway.
What is the best way to handle database connection?
4 Answers1remove the public getConnection method, if it used outside the Database class you really have a design problem.2remove the commit method. ... 3remove the instance variable connection , instead obtain a connection per call.4and properly close this connection in the finally block of each call.
Should I close DB connection after query?
Don't close your connection unless you are exiting your app, and then make sure you do. Ensure that you are using the same connection when you come back to do more I/O. Database connections are resource-intensive and should be established as few times as possible and shared as much as possible.
Which function is used to open a database connection?
1. Create database connection. To create a database connection in PHP, use the function mysqli_connect(). It takes four arguments: server name, username, password, database name.
Related Questions
-
Anonymous2 weeks ago
Expert answer2 weeks ago -
Anonymous2 weeks ago
Expert answer2 weeks ago -
Anonymous2 weeks ago
Expert answer2 weeks ago -
Anonymous2 weeks ago
Expert answer2 weeks ago -
Anonymous2 weeks ago
Expert answer2 weeks ago -
Anonymous2 weeks ago
Expert answer2 weeks ago -
Anonymous2 weeks ago
Expert answer2 weeks ago