PHP MySQL Transaction implementation Program _php tutorial

Source: Internet
Author: User
The condition for this feature is that the environment MySQL 5.2/php 5 support Transaction table type needs to InnoDB, with these conditions you can do the above implementation, this thing rollback operation is often used in large projects, such as banks, e-commerce will be used, the need for friends can refer to.

Recent project software upgrade to support transaction processing, do an example for everyone to learn the reference
Environment MySQL 5.2/php 5
The table type that supports transactions requires InnoDB

The code is as follows Copy Code

$LinkID =mysql_connect (' localhost:3307 ', ' root ', *******);
mysql_select_db (' Web_his ', $LinkID);
mysql_query ("Set names UTF8");

/* Create transaction */
mysql_query (' START TRANSACTION ') or exit (Mysql_error ());
$ssql 1= "INSERT into pf_item values (' 22 ', ' we ', ' 30 ')"; Execute SQL 1
if (!mysql_query ($ssql 1)) {
echo $ssql 1.mysql_errno (). ":". Mysql_error (). "
";
mysql_query (' ROLLBACK ') or exit (Mysql_error ());//Determine rollback when execution fails

Exit
}
$ssql 1= "INSERT into pf_item values (' + ', ' hell ', ' 10 ')"; Execute SQL 2
if (!mysql_query ($ssql 1)) {
echo $ssql 1.mysql_errno (). ":". Mysql_error (). "
";
mysql_query (' ROLLBACK ') or exit (Mysql_error ());//Determine rollback when execution fails

Exit
}

mysql_query (' COMMIT ') or exit (Mysql_error ());//Execute transaction

Mysql_close ($LinkID);
?>

http://www.bkjia.com/PHPjc/632945.html www.bkjia.com true http://www.bkjia.com/PHPjc/632945.html techarticle The condition for this feature is that the environment MySQL 5.2/php 5 support Transaction table type needs to be innodb, with these conditions you can do the above implementation, this thing rollback operation is big item ...

  • 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.