Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not sure I can answer your specific question, but wanted to suggest that global / singleton connection objects may not be the best idea if this if for a web-based system. DBMSs are generally designed to manage large numbers of unique connections in an efficient manner. If you are using a global connection object, then you are doing a couple of things:</p> <ol> <li><p>Forcing you pages to do all database connections sequentially and killing any attempts at asyncronous page loads. </p></li> <li><p>Potentially holding open locks on database elements longer than necessary, slowing down overall database performance.</p></li> <li><p>Maxing out the total number of simultaneous connections your database can support and blocking new users from accessing the resources.</p></li> </ol> <p>I am sure there are other potential consequences as well. Remember, this method will attempt to sustain a database connection for every user accessing the site. If you only have one or two users, not a problem. If this is a public website and you want traffic then scalability will become an issue.</p> <p><strong>[EDIT]</strong></p> <p>In larger scaled situations, creating new connections everytime you hit the datase can be bad. However, the answer is not to create a global connection and reuse it for everything. The answer is connection pooling. </p> <p>With connection pooling, a number of distinct connections are maintained. When a connection is required by the application the first available connection from the pool is retrieved and then returned to the pool once its job is done. If a connection is requested and none are available one of two things will happen: a) if the maximum number of allowed connection is not reached, a new connection is opened, or b) the application is forced to wait for a connection to become available.</p> <p><strong>Note:</strong> In .Net languages, connection pooling is handled by the ADO.Net objects by default (the connection string sets all the required information). </p> <p>Thanks to Crad for commenting on this.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload