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 tutorial
$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 ();
}
We will use a commit to provide the transaction with the rollback to roll back and forth the failed thing.