Mysql_query ("begin"); // starts a transaction.
Mysql_query ("set autocommit = 0"); // you can specify that the transaction is not automatically committed.
$ Insert = "insert into userinfo values ('aa12', 'A', '1', 'aaa ')";
Mysql_query ($ insert );
Mysql_query ("commit"); // in non-autocommit mode, you must manually execute commit to make the operation take effect.
// Mysql_query ("set autocommit = 0 ");
$ Insert = "insert into userinfo values ('aa20', 'AA', '1', 'aaa ')";
$ Insert = "insert into userinfo values ('aa8', 'A', '1 ')";
// Mysql_query ("commit ");
If (mysql_num_rows = 0)
Mysql_query ("rollback"); // in non-autocommit mode, rollback is executed to invalidate the transaction operation.
Else echo "OK ";
// Mysql_query ("close ");
Mysql_query ("set autocommit = 1"); // restore autocommit Mode
$ Insert = "insert into userinfo values ('aa15', 'A', '1', 'aaa ')";
Mysql_query ($ insert); // you do not need to manually execute commit to make the transaction take effect.
After the begin command is executed, set autocommit = 0, and set autocommit = 0 or 1 is invalid. Therefore, in order to make the operation clear, do not use begin.