|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
Say, we have a website whose every page involves a connection with a MySql database.
Q1. If we open a connection to the database and retrive some data however forget to close the connection and result set, how bad is that? Disadvantages? Q2. If we dont close the connection would it be closed automatically when the page exits? Q3. If most of the pages involve a connection with the database can it be a potential 'advantage' if i dont close the connection and recordset in every page because maybe he saves the time to reconnect or something. (This is just my assumption, please correct me if i am wrong)? Thank you Neville |
|
#2
|
|||
|
|||
|
I think php automatically closes the connection when the script finishes executing otherwise bad scripts would quickly eat resources. If you want someone to establish a permanent connection you can use the mysql_pconnect function instead.
-KM- |
|
#3
|
|||
|
|||
|
There is really no quick recipie for this, however, a couple things to remember.
1 - PHP closes the mysql connection after the script is done... I would not rely on this as it is not safe to rely on php for this action, nor is it elegant. 2 - If you are connecting to the mysql server locally then there is no problem in making a connection on each request (although, if you can do without a connection that is even better). 3 - pconnect does not solve all your problems. Normally you do not want to use pconnect unless you absolutely have to. In cases where you would have many (more than 20) open tables at one time, you probably don't want to use pconnect.
__________________
__________________________________________________ _ Wil Moore III, MCP | Integrations Specialist | Senior Consultant Are You Listed...? | DigitallySmooth Inc. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Few questions about PHP connection to MySql... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|