jason213123 Posted August 2, 2010 Share Posted August 2, 2010 hi, i need know if there is any way to lock a record for exclusive editing in mysql for other user can´t edit the same record at same time. The ideia is before the user edit the record he see that the current record is open for other user. it´s possible to do something like this? thanks a lot for your help Link to comment https://forums.phpfreaks.com/topic/209564-detect-if-a-record-is-open-by-other-user/ Share on other sites More sharing options...
xcoderx Posted August 2, 2010 Share Posted August 2, 2010 yes set time for post or edit maybe? Link to comment https://forums.phpfreaks.com/topic/209564-detect-if-a-record-is-open-by-other-user/#findComment-1094041 Share on other sites More sharing options...
AbraCadaver Posted August 2, 2010 Share Posted August 2, 2010 You could have a lock table that stored the tables and ids of rows that are locked and the time of when they were locked. This would need to expire at some point in case someone opened an edit form and then went to lunch or whatever. Link to comment https://forums.phpfreaks.com/topic/209564-detect-if-a-record-is-open-by-other-user/#findComment-1094179 Share on other sites More sharing options...
radar Posted August 2, 2010 Share Posted August 2, 2010 or perhaps add in a field 'in_editing' with a 1 or 0 avail.. when someone attempts to open a record, it checks that field using the WHERE clause, ie: WHERE in_editing = '0'; if in_editing = 0 { // grant permission to edit. // update the field to 1 } else { // sucks to be you! move faster next time! } though like Abra points out this leads to trouble. if someone opens it up, then goes to lunch or whatever it's still locked so no one can modify that record.. so in that case you'd want to add a time_lock field in it, with datetime parameter set.. when you update the in_editing to 1 you also set the time_lock to now() then you would have to create a cron job say every other hour, to run and modify this time_lock field to blank, and the in_editing firled to 0. Link to comment https://forums.phpfreaks.com/topic/209564-detect-if-a-record-is-open-by-other-user/#findComment-1094184 Share on other sites More sharing options...
AbraCadaver Posted August 2, 2010 Share Posted August 2, 2010 then you would have to create a cron job say every other hour, to run and modify this time_lock field to blank, and the in_editing firled to 0. Or just check the lock time the next time a user goes to edit the record. If its greater than 5 minutes or whatever then remove the lock. No need for cron. Link to comment https://forums.phpfreaks.com/topic/209564-detect-if-a-record-is-open-by-other-user/#findComment-1094207 Share on other sites More sharing options...
radar Posted August 2, 2010 Share Posted August 2, 2010 that works too. Link to comment https://forums.phpfreaks.com/topic/209564-detect-if-a-record-is-open-by-other-user/#findComment-1094210 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.