The PHP code for implementing transaction processing data can also be described as the mysql transaction processing code. The PHP code for implementing transaction processing data can also be described as the mysql transaction processing code.
Script ec (2); script
Public function insertUser ($ userArray ){
Foreach ($ userArray as $ key => $ value ){
@ $ Field. = "$ key ,";
@ $ Content. = "'$ value ',";
}
$ Field = ereg_replace (', $', '', $ field );
$ Content = ereg_replace (', $', '', $ content );
$ Db = db_connect (); // database connection tutorial
$ Db-> autocommit (FALSE); // set to non-automatic commit-Transaction Processing
$ Sql1 = "insert into t_user (". $ field. ") VALUES (". $ content .")";
$ Result1 = $ db-> query ($ sql1 );
$ Sql2 = "insert into t_userpost (f_username) VALUES ('". $ userArray ['f _ username']. "')";
$ Result2 = $ db-> query ($ sql2 );
If ($ result1 & $ result2 ){
$ Db-> commit (); // all succeeded. The execution result is submitted.
Echo 'Submit ';
} Else {
$ Db-> rollback (); // If any error occurs, roll back and cancel the execution result.
Echo 'rollback ';
}
$ Db-> close ();
}
We will use commit to provide transactions and rollback failures.