Only InnoDB and BDB types of data tables in MySQL can support transaction processing! Other types are not supported!
| The code is as follows |
Copy Code |
Public Function Insertuser ($userArray) { foreach ($userArray as $key => $value) { @ $field. = "$key,"; @ $content. = "' $value '"; } $field = Ereg_replace (', $ ', ', $field); $content = Ereg_replace (', $ ', ', $content);
$db = Db_connect (); Connecting to a database
$db->autocommit (FALSE); Set to non-autocommit-transaction processing $sql 1 = "INSERT into T_user (". $field. ") VALUES (". $content."); $result 1 = $db->query ($sql 1);
$sql 2 = "INSERT into T_userpost (f_username) VALUES (') $userArray [' F_username ']." $result 2 = $db->query ($sql 2);
if ($result 1 && $result 2) { $db->commit (); All successful, submit execution results echo ' Submit '; } else { $db->rollback (); Any errors occur, rollback, and cancel execution results echo ' Roll back '; } $db->close (); } |