Hi,

For an application that I'm working on, I wan't users to be able to show content even while an editor/administrator makes changes in one of my database's tables. But if another editor tries to load the same content for editing, he/she shouldn't be able to do this.

I've been reading up on MySQL's internal LOCK command, but it doesn't seem to be what I need. I need a read/write lock based on what the current user/editor want's to do, and not only based on what content an editor is working with at the moment.

I'm thinking of the following solution:

Create a new database:

CREATE TABLE table_lock
(
        table_name VARCHAR(40),
        table_id INT,
        PRIMARY_KEY (table_name, row_id)
        
);

And two functions:

set_lock($table_name, $row_id), check_lock($table_name, $row_id) and release_lock($table_name, $row_id). Whenever an editor opens some content for editing, check_lock() will be called to se if table_lock contains a row with the same table_name and row_id. If, the content isn't loaded and the editor is told that someone else is working on the content, and are asked to try again later. If not, set_lock() is called to make sure that no other editor opens the content before it's saved and release_lock() is called, which will remove the line from table_lock again.

Is this a good way to do this? Or are there any other suggestions?

--
anders thoresson

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to