Accessing the database concurrently in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
techielog
Forum Newbie
Posts: 1
Joined: Wed Oct 26, 2011 4:37 pm

Accessing the database concurrently in php

Post by techielog »

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.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Accessing the database concurrently in php

Post by social_experiment »

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
Post Reply