Jump to content

MySQL Database connection strategy


eazyGen

Recommended Posts

Hi guys.

 

I am generally familiar with databases (mostly DB2), but I am a newbie when it comes to PHP and MySQL.

 

I notice that in order to use a MySQL databases, a connection must first be made to the database and, somewhere along the line, that connection needs to be closed.

 

I am thinking that to open a connection at the start of a script and then to close it at the end will work. However, if I do this for each and every script that accesses a database table, then there will be numerous open and close statements running through my application.

 

I am wondering therefore is there is a generally accepted strategy for handling a database that minimises the amount of connection statements; or if the above is essential given the static state nature of a web page.

 

Any assistance much appreciated.

 

S

 

Link to comment
Share on other sites

MySQL has an extremely fast and lightweight connection process.  Since PHP has "page scope" and a typical php script runs very quickly, there is really no reason to worry about closing mysql connections, as the connection resource will be garbage collected when the script completes. 

Link to comment
Share on other sites

MySQL has an extremely fast and lightweight connection process.  Since PHP has "page scope" and a typical php script runs very quickly, there is really no reason to worry about closing mysql connections, as the connection resource will be garbage collected when the script completes.

Many thanks.

 

I am using Apache and mySQL on my server and localhost. Is there any way I can see the number of open database connections on either or both?

 

S

Link to comment
Share on other sites

The commands:

 

show processlist;

 

or

show full processlist;

Hi.

 

My apologies. I did not make myself clear.

 

I assume the above are for command line access.

 

Is there a way I can see this via a URL, or perhaps from phpMyAdmin?

 

Thanks

 

S

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.