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
Post a Comment