Anonymous Asked in Cars &Transportation · 2 weeks ago

When should I open a database connection?

Keeping connections open can increase the chance that part of your code will accidentally, or maliciously through the actions of others, cause unwanted queries to be performed on the database. That being the case, you should only open the connection before you want to run your queries. 14 июл. 2009 г.


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

Relevance
Write us your question, the answer will be received in 24 hours