PHP transaction processing data implementation code. The copy code is as follows: publicfunctioninsertUser ($ userArray) {foreach ($ userArrayas $ key $ value) {@ $ field. $ key,; @ $ content. $ value,;} $ fieldereg_replace (,
The code is as follows:
Public function insertUser ($ userArray ){
Foreach ($ userArray as $ key => $ value ){
@ $ Field. = "$ key ,";
@ $ Content. = "'$ value ',";
}
$ Field = ereg_replace (', $', '', $ field );
$ Content = ereg_replace (', $', '', $ content );
$ Db = db_connect (); // connect to the database
$ 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 ();
}
The http://www.bkjia.com/PHPjc/321765.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/321765.htmlTechArticle code is as follows: public function insertUser ($ userArray) {foreach ($ userArray as $ key = $ value) {@ $ field. = "$ key,"; @ $ content. = "'$ value'," ;}$ field = ereg_replace (',...