Two SQL statements are executed in a piece of code, which means two SQL statements are to be matched, but today there are some problems. please refer to the content. because there are many database fields, let me make an analogy.
Detailed information table list
The user table has a field num.
I am executing a method that inserts a piece of data into the list, and at the same time to the num + 1 of the user table
There were approximately 20 million registered users last month. I calculated the numbers in these user list tables and compared them with num in the user table.
The comparison result shows the number of list data records of approximately 70 persons, which is about 10 less than the number recorded by num.
This is because the methods are executed sequentially.
Public function test (){
Insert $ data;
Update num + 1;
}
Insert to list first, and then update the user num field
I would like to ask under what circumstances will this happen if the data is not synchronized. Please do not paste the code.
Reply to discussion (solution)
You should use transactions.
Undo the operation if insert $ data or update num + 1 fails.
Is Transaction processing used? Determine whether to update the field after successful insertion
Insert $ data; if it fails, but update num + 1 is still executed; then it will be inconsistent.
Is Transaction processing used? Determine whether to update the field after successful insertion
Insert $ data; if it fails, but update num + 1 is still executed; then it will be inconsistent.
Big Brother: generally, it will fail under any circumstances. it is an insert statement with the user name as the mobile phone number. Fields can also be empty.
The mobile phone number is repeated. if the write value and field type are inconsistent, the operation may fail.
You should filter user data before writing data to the database.
The mobile phone number is repeated. if the write value and field type are inconsistent, the operation may fail.
You should filter user data before writing data to the database.
It must have been filtered out. I wrote a monitoring report that day, but now there is no problem. when there is a problem, I will know what the problem is, thanks buddy.