I'm using PHP, MySQL (just like u.)
The problem is in one of my functions.
I'm sending 2 different query to the database.
I want to them executed both, or be rolled back.
In my function the code is like that....
Code: Select all
<?php
$q1 = "INSERT INTO tbname1 VALUES ($bla1, $bla2, $bla3)";
// where $bla1 is key
Execute_Query($q1) ? $flag1 = true : $flag1 = false;
$q2 = "UPDATE tbname2 SET VALUES fld1 = fld1+1"
// fld1 is the field of the table tbname2
Execute_Query($q1) ? $flag2 = true : $flag2 = false;
if($flag1 && $flag2)
return true;
if(!$flag1 && $flag2){
$q4 = "UPDATE tbname2 SET VALUES fld1 = fld1-1"
Execute_Query($q4);
}
if($flag1 && !$flag2){
$q3 = "DELETE FROM tbname1 WHERE fld1 = $bla1";
Execute_Query($q3);
}
return false;
?>But the problem rises here. There is a possibility to fail queries for $q3 and $q4.
P.S : I have changed the code a little bit, the above code can be written in better format. But even this case, the problem is same.
BIG DEAL : WHAT IF THE ROLL BACK STATEMENT FAILS?