Explain the code case of transaction rollback implemented by phpPDO

Source: Internet
Author: User
This article mainly introduces the transaction rollback function implemented by phpPDO, and analyzes the SQL statements and operation skills related to the function of implementing transaction rollback by php based on the PDO operation in combination with the specific instance form, for more information about the transaction rollback function implemented by php PDO, the SQL statements and operation skills related to implementing the transaction rollback function of php based on PDO operations are analyzed based on the specific instance form. For more information, see

This example describes the transaction rollback implemented by php PDO. We will share this with you for your reference. The details are as follows:

$ Servername = "localhost"; $ username = "root"; $ password = "admin"; $ dbname = "test"; try {$ conn = new PDO ("mysql: host = $ servername; dbname = $ dbname ", $ username, $ password); $ conn-> setAttribute (PDO: ATTR_ERRMODE, PDO: ERRMODE_EXCEPTION ); // start the transaction $ conn-> beginTransaction (); $ conn-> exec ("insert into 'hello' ('firstname', 'lastname', 'Email ') VALUES ('Ye ', 'xiaming', 'yexianming @ 163.com') "); $ conn-> exec (" insert into 'hello' ('firs Tname', 'lastname', 'Email ') VALUES ('Ye', 'cong', 'yecong @ 163.com ')"); $ conn-> exec ("insert into 'hello' ('firstname', 'lastname', 'Email ') VALUES ('fang', 'meng ', 'fangmeng @ 168.com ') "); // submit the transaction $ conn-> commit (); echo" New records created successfully! ";} Catch (PDOException $ e) {// roll back the transaction $ conn-> rollBack (); echo $ SQL ."
". $ E-> getMessage () ;}$ conn = NULL;

The above is a detailed description of the code case of transaction rollback implemented by php PDO. For more information, see other related articles in the first PHP community!

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.