Jump to content

detect if a record is open by other user?


jason213123

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.