Trouble using MySQL transactions with loops in PHP -


i trying set mysql transaction such can loop through bunch of queries (see below) , if of them fail, rollback of changes. finding if 1 fails, not of queries rolled back. doing wrong here?

mysql_query("start transaction");       foreach($array1 $arr){            // loop sql query            if(mysql_error()){                $failed = "...";           }      }        foreach($array2 $arr){            // loop sql query            if(mysql_error()){                $failed = "...";           }      }       if(isset($failed)){           mysql_query("rollback");      } else {           mysql_query("commit");      } 

thanks!

the reason if query fails (due error), transaction automatically rolled , terminated. should stop looping if query fails, because executing after failed query autocommit (or @ least in transaction if autocommit off)...


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -