Implementing self-value PHP transaction data implementation code

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.