need help with table lock - could this be performed with mysql commands or do I to write my own PHP function

From: Date: Sun, 10 Aug 2003 12:53:31 +0000
Subject: need help with table lock - could this be performed with mysql commands or do I to write my own PHP function
Groups: php.general 
Request: Send a blank email to php-general+get-159027@lists.php.net to get a copy of this message
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

« previous php.general (#159027) next »