Whether database data writing and non-database operations need to be controlled by transactions, or other better methods

specific scenario: you need to write a piece of data to the database and upload an image at the same time. The name of the picture is the ID, to which the data is written. If the upload of the picture fails, do not write this data either.

solution: 1, if the picture fails to upload, delete the data (what if the deletion fails? I wrote it in the catch code of try {} catch {})
2, using database transaction processing, catch to error, and roll back

directly.

I think the second kind is a little safer. I don"t know how the gods usually deal with this problem.

Apr.08,2021

if all your business uses stored procedures, of course it is consistent

but be reasonable. If everything else is coded, you can still handle it according to normal code

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e48aa5-59d1f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e48aa5-59d1f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?