Copy the Code code 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 (); Connecting to a database
$db->autocommit (FALSE); Set to non-auto commit--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 error occurred, rollback and cancel execution result
echo ' rollback ';
}
$db->close ();
}
The above describes the implementation of self-value PHP transaction data implementation code, including the realization of self-worth of content, I hope that the PHP tutorial interested in a friend helpful.