php - How does the database determine whether a piece of data has been modified?
大家讲道理
大家讲道理 2017-07-07 10:35:07
0
7
1622

A and B access a set of data on the same page at the same time. A has modified one of the data. B's page has not been refreshed, so the information B sees is before A's modification. At this time, B also needs to modify this piece of data. How can I remind B that this piece of data has been modified.

I saw a way to find this data based on the last modified time before modifying the data (select * from xxx where updatetime = xxx and id= xxx). If it cannot be found, it means it has been modified. Check The description has not been modified when it arrives.

I would like to ask if there is a better way?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(7)
typecho

I remember that optimistic locking in hibernate is implemented using the version number field. After each update is successful, the value of the version number field is incremented by 1.
Before updating, first check whether the version number in the database and the version number saved in the page are the same. , if the version number becomes larger, the user is prompted that other users have modified the data during editing.

Of course, you can also use pessimistic locking. When entering the page, use select... for update to lock the record. At this time, other users cannot edit the locked record at the same time.

伊谢尔伦

I will do this - add a field, edit_num, +1 for each change, and compare it when B needs to be changed.

黄舟

Optimistic Lock Optimistic Lock Optimistic Lock

给我你的怀抱

Optimistic locking mechanism is implemented by adding a version field to the data

大家讲道理

Add a field to the data tableupdate_atThe type is TIMESATMP, the default value is CURRENT_TIMESTAMP, no other changes are needed
Whenever the data is updated, the value will be updated automatically

女神的闺蜜爱上我

Add a version field to this data. The version number starts from 0 by default. It will increment automatically if it is not modified. Just verify whether this version is consistent with the version in the database each time it is submitted.

为情所困

Add a version number field to the xxx table

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template