I have created form which contains lots of fields . I am storing the fields in various tables . I have written insert queries for all the tables separately in a single function . I should make sure that all the queries are executed . In case the queries are partially executed i should delete all the values inserted through partial execution . How do i do this ?
You need MySql transactions (not clear what you use, PDO or mysqli_* )
/* START TRANSACTION; */
try {
foreach ($fields as $field) {
// INSERT / UPDATE
/* COMMIT; */
}
} catch (Exception $e) {
echo $e;
/* ROLLBACK; */
}
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.