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

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

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

unit testing - How to mock PreferenceManager in Android? -