How to control documents in a BD that can be edited by multiple users?

Hi,

We have documents in a cloud software that can be edited by multiple users at the same time (invoices, quotes, etc...). We need to find a solution for this, since these documents can be inconsistent.

For now we considered Mutex, but we don't know if there are any other possibilities for doing this (Merging algorithms or anything else). Everything is being saved in a mysql database.

Regards!
dimensionavAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gr8gonzoConsultantCommented:
Stupid question - have you considered using Google Docs?
0
dimensionavAuthor Commented:
Hi,

I think you misunderstood my question, I mean that the documents are not saved as files, they are DB tables (Invoice_header,Invoice_details, you know...). When you have a Form in PHP and you store it in a Database, and when there are multiple users doing the same, that's the reason of the question.

Sorry for not being so explicit.


Regards!
0
gr8gonzoConsultantCommented:
So what I'm hearing is:

1. You have one DB table that contains data submitted from a web form.
2. Each form submission is a record in that DB table.
3. Each record can be edited by a user.
4. If you have more than one user editing the same record, you have problems where users overwrite each other's changes.
5. You have a custom solution for editing the records.

Is that a correct understanding of the problem that you are trying to solve?
0
Increase Security & Decrease Risk with NSPM Tools

Analyst firm, Enterprise Management Associates (EMA) reveals significant benefits to enterprises when using Network Security Policy Management (NSPM) solutions, while organizations without, experienced issues including non standard security policies and failed cloud migrations

dimensionavAuthor Commented:
Yep, that's the correct meaning of what I tried to say.

Regards!
0
gr8gonzoConsultantCommented:
The solution, then, is to implement two new columns in your database table that are called something like "locked_on" (an integer field) and "locked_by" (also an integer field that points to the table containing your users).
The names can be up to you - those are just suggestions.

Make it a When a user goes to edit the record, update the record and set locked_by to the user's ID and set locked_on to the UNIX timestamp (the function to get this in PHP is simply time() without any parameters), and in your WHERE clause, specify both the record ID and also locked_on is null. The query should look something like this:

$query = "UPDATE <your table> SET locked_on=".time().",locked_by=$variable_containing_current_user_id WHERE record_id=$var_containing_record_id_to_edit AND locked_on IS NULL";

Run that query, and then check the number of affected rows. If the # of affected rows is 0, then it means that someone else already grabbed that record and is working on it because locked_on has a timestamp in it (it isn't null). If the # of affected rows is 1, then it means you've acquired a lock on that particular record, and the user is now free to edit it.

Once the user is finished editing it, clear the timestamp when the record is updated:

$query = "UPDATE <your table> SET <your other fields>, locked_on = NULL, locked_by = NULL WHERE record_id=$var_containing_record_it_to_save";

You may also have a situation where someone closes their browser without saving, and the locked_on/locked_by isn't cleared. That said, you can always clear the fields automatically if the locked_on timestamp is older than a certain # of seconds (e.g. 600 seconds or 10 minutes or however long it normally takes a user to work on a record). If you do this, then while the user's browser is active and editing that record, use AJAX to send regular updates to the database every couple of minutes, updating the value of locked_on to the current timestamp.

This way, someone can work on the record as long as they need to, as long as their browser is open and their internet connection is up. While they're working, their browser is telling the database that the lock is still good. If their computer crashes, they can even re-edit the same record as long as they still have the lock.

And once the user finishes, and the locked values are cleared, the record becomes available for someone else to grab it.

There are some additional things you can implement to make the solution more robust, but those are the basic concepts.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jimyXCommented:
Do you want to know who is Editing what? Or just you need to know if the current record is in Edit Mode by one user?
If yes you need to know who is editing, then, do you create DB-user for the users? Or you create one user that establishes every connection?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Cloud Services

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.