MySQL doesn't have built in row-level locking, but they are chaning that.
The best thing to do, for now, is to have a record_locked column, and set it
to 1 if the record is in use. To lock the record, you would run a query like
update table_name set record_locked = 1 where id = ??? and record_locked = 0
'id' is an auto increment column, so each row has a unique id. If the record
is locked, the query will return 0 rows affected, and you wait a while. If it
is not yet locked, and the query changes it, it will return 1 row affected,
and you now know you have a lock on it.
Another note. Something to experiment with, but I'm not sure this is
guarenteed behavior, so tread carefully; this was an accidental discovery.
This query should also work:
update table_name set record_locked = 1 where id = ???
If the record_locked column is already 1, it won't set it to one again, so
you might not need the 'and record locked = 0' part of the query, but I'd use
it to be safe.
Hope that helps.
j----- k-----
On Friday 12 January 2001 05:34, Martin Thoma wrote:
> Hello !
>
> I want to make something like: There is one server and seval clients,
> which all access the same database. The problem: If one user changes a
> record, no other user should be able to change it.
>
> Whats the general way to do it with MySQL ?
>
> Regards
>
> Martin
--
Joshua Kugler
Associated Students of the University of Alaska Fairbanks
Information Services Director
[EMAIL PROTECTED]
907-474-7601
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php