php - mysql_query() transaction simple example -


i'd use transaction in code. doesn't work.

in simple base have table called "persons" 2 columns (person_id, name) , has no data yet.

mysql_query("set autocommit=0"); mysql_query("start transaction");  $a1 = mysql_query("delete persons person_id='5'"); $a2 = mysql_query("delete persons person_id='1'");  if ($a1 , $a2) {   mysql_query("commit");   echo "this commit"; } else {         mysql_query("rollback"); echo "this rollback"; }  } 

when i'm deleting person have 5th , 1st person_id, should goto rollback because have no data in base(base totally empty), browser displaying "this commit".

how can fix transaction.

by using mysql_affected_rows can check if rows affected or not.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -