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.