I use the exec update data from PDO to get the number of rows affected
But there is a problem, if the update data is the same as the original data returned is 0
So I can't tell if it's the same as the data update or the data is not updated to the result
You must confirm it again with a query statement
Is there a simpler solution? (As long as the method of pdo,php comes back to the modified state)
Reply to discussion (solution)
Check again for confirmation is not as straightforward as updating
If the update fails, an error occurs
So you should always check the return value of Pdo::errorcode.
Pdo::exec returns 0 indicates that the operation was successful, but no actual action
If the update fails, an error occurs
So you should always check the return value of Pdo::errorcode.
Pdo::exec returns 0 indicates that the operation was successful, but no actual action
EXEC returns three states, updates to data will return an affected number of rows, no update data will return 0, error will return False (the tables that are not in the database are necessarily updated)
The first two states, ErrorCode, return 00000 and cannot be judged at all.
To make my question a little more straightforward.
' User ' database
ID Password
1 boy
Update ' user ' set ' password ' = ' boy ' where ' id ' = ' 1 ';
EXEC returns 0,errorcode return 00000
This would not be good if you told the direct user settings failed.
I would have to select ' Password ' from ' user ' where ' id ' = ' 1 ';
If password== ' boy ' setting succeeds, other settings fail
Uh! So long no one answered!!
Think of a way to do this: Add an Update Time field to the table, and set it to the time of day when you update it
This makes it possible to distinguish between returning and modifying the same data when there is no record in the Update table, which is 0, which requires a query validation problem.
This is a flexible approach, and at the moment it seems the simplest