I'd like to use transaction in my code. But it doesn't work.
In my simple base i have table called "persons" with 2 columns (person_id, name) and it has no data yet.
mysql_query("SET AUTOCOMMIT=0");
mysql_query("START TRANSACTION");
$a1 = mysql_query("DELETE FROM persons WHERE person_id='5'");
$a2 = mysql_query("DELETE FROM persons WHERE person_id='1'");
if ($a1 and $a2) {
mysql_query("COMMIT");
echo "this is commit";
} else {
mysql_query("ROLLBACK");
echo "this is rollback";
}
}
When i'm deleting person which have 5th and 1st person_id, it should goto the ROLLBACK because i have no data in base(base is totally empty), but browser is displaying "this is commit".
How can i fix this transaction.