Re: [PHP] need help with table lock - could this be performed with mysql commands or do I to write my own PHP function
* Thus wrote anders thoresson ([EMAIL PROTECTED]): 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. What happens when the user doesn't finish editing or the browser simply crashes on him? If you do use this method, it needs to be atomic. if two users access the page at the same time they both will pass the check_lock() function but only one will pass set_lock(), if the database constraints are enforced. You'd want something like: if (! set_lock() ) { // table is already locked } else { // we have the lock } Curt -- I used to think I was indecisive, but now I'm not so sure. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] need help with table lock - could this be performed with mysql commands or do I to write my own PHP function
What happens when the user doesn't finish editing or the browser simply crashes on him? Well. Didn't think of that. So how can I avoid that two editors loads the same record for editing at the same time, while still making all records available for regular visitors to read? -- anders thoresson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] need help with table lock - could this be performed with mysql commands or do I to write my own PHP function
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