Re: Concurrent update to database (PostgreSQL or MySQL) ??
| From: | (Miles Thompson) | Date: | Wed, 18 Apr 2001 12:15:08 +0000 |
| Subject: | Re: Concurrent update to database (PostgreSQL or MySQL) ?? | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-8651@lists.php.net to get a copy of this message | ||
This is a database, not a PHP question. Different databases have different locking/buffering schemes. So which are you using, and what do the documents say about locking? Do they lock records or pages?
Generally you never attempt to lock a record until you are ready to write to it. In general terms, if this is a record that would be hit by a lot of users, here's a fairly foolproof method:
Establish a loop which checks to see if the record is locked. This avoids failure of attempting to lock an already locked record. You may have to provide for timing out if the record is never freed.
When record becomes free, lock it.
Execute your write.
Unlock the record.
On the other hand.
Hope this helps - Miles
PS You almost never lock a record for a read.
At 01:47 PM 4/18/01 +0200, Nicolas Guilhot wrote:
Hi, How can I avoid two or more users to update the same record at the same time ? Ideally, I would like to lock the record when a user open it for modification. So if another user try to open the same record he'll be warned or get record values as read only. Is this possible and how to do it with PHP ?? How can I know that the user that has locked the record has finished with it, if he never commits his changes ? Is there an FAQ about this ? Regards, Nicolas -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net For additional commands, e-mail: php-db-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net