How to determine if Mysql update succeeded with PDO PHP?
Check affected rows
$sth->rowCount();
This would only work if the updated row has changes, but what if the row is unchanged?? Then $sth->rowCount()
would return 0
even if the update has succeeded...
The normal way to do this would be to construct a COUNT query on the same criteria, and run it before your UPDATE.
This could be subject to race conditions depending whether you're running in a transaction, and if so on the isolation level. So the real answer depends what you need the number for.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.