mysql_query ("Begin");//Start a transaction
mysql_query ("SET autocommit=0"); Set transaction not automatic commit
$insert = "INSERT INTO UserInfo VALUES (' aa12 ', ' AA ', ' 1 ', ' aaa ')";
mysql_query ($insert);
mysql_query ("commit");//non-autocommit mode, you must manually perform a COMMIT to make the operation effective
mysql_query ("SET autocommit=0");
$insert = "INSERT INTO UserInfo VALUES (' aa20 ', ' AA ', ' 1 ', ' aaa ')";
$insert = "INSERT INTO UserInfo VALUES (' aa8 ', ' AA ', ' 1 ')";
mysql_query ("COMMIT");
if (mysql_num_rows==0)
mysql_query ("ROLLBACK");//non-autocommit mode, execution ROLLBACK invalidates the transaction operation
else echo "OK";
mysql_query ("CLOSE");
mysql_query ("SET autocommit=1");//restore autocommit mode
$insert = "INSERT INTO UserInfo VALUES (' aa15 ', ' AA ', ' 1 ', ' aaa ')";
mysql_query ($insert);//Do not need to perform commit manually to take the transaction operation into effect
After the begin, it works with set autocommit=0, and after that setting set autocommit=0 or 1 o'clock is not valid. Therefore, to make the operation clear, the begin is generally not used.
http://www.bkjia.com/PHPjc/321129.html www.bkjia.com true http://www.bkjia.com/PHPjc/321129.html techarticle mysql_query ("Begin");//Start a transaction mysql_query ("Set autocommit=0");//SET Transaction not automatic commit $insert = "INSERT INTO UserInfo VALUES (' aa12 ', ' AA ', ' 1 ', ' AAA '); Mysql_query ($ ...