Hi,
I am new to php or server side processing. I have one question in php. When there are 100's of users accessing the same database for inserting a record, how should we maintain the connections with single user name?
From my understanding, we can do that in following ways
1) Use single user name to connect/disconnect/insert record into mysql database for all users. I understand it is not efficient way for doing all users.
2) use single user name and connect only at first time page loads and maintain the connection for certain time and disconnect the connection after certain period of idle time and then disconnect automatically if needed.
Which one of the approach is better? If the above two approaches are wrong, then what is the right method for accessing database concurrently without much resource overhead on the system.
Please help me.
Accessing the database concurrently in php
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Accessing the database concurrently in php
You don't say what type of database you will be using so i'll explain my reasoning at the hand of mySQL and mysql_connect(). With mysql_connect() a connection is created if none exists and the existing connection is used if found. This seems to correspond with your second point; If i'm not mistaken as soon as a user closes their page the connection would be closed automatically
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering