Use mysql transaction features to maintain data consistency in php

Source: Internet
Author: User
The InnoDb data table of mysql supports transaction, that is, it is successful only when a series of operations are successful. Otherwise, the data is returned to the state of all the uncommitted data. This is useful when it comes to data involving money. The following describes the specific practices in php. mysql InnoDb data tables (& quot; begin & quot;); $ mysql support transactions, that is to say, if a series of operations are supported successfully, the operation is successful. Otherwise, the system returns to the status of all the data that has not been submitted. This is useful for data involving money. The following describes the specific practices in php,
Mysql_query ("begin"); $ rs1 = mysql_query ("insert into cd_test (uname, age) values ('A', 1 )"); $ rs2 = mysql_query ("insert into cd_test (uname, agef) values ('CC', 'CD ')"); // if ($ rs1 & $ rs2) {mysql_query ("COMMIT"); // submit and confirm echo "added successfully ";} else {mysql_query ("ROLLBACK"); // roll back echo "failed to add";} mysql_query ("end ");

 

 

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.