Hello all,
I am trying to set up a MySQL transaction such that I can loop through a bunch of queries (see below) and if any of them fail, rollback all of the changes. I am finding however that if one fails, not all of the queries are rolled back. Am I doing anything wrong here?
mysql_query("START TRANSACTION");
foreach($array1 as $arr){
// loop SQL query
if(mysql_error()){
$failed = "...";
}
}
foreach($array2 as $arr){
// loop SQL query
if(mysql_error()){
$failed = "...";
}
}
if(isset($failed)){
mysql_query("ROLLBACK");
} else {
mysql_query("COMMIT");
}
Thanks!