Transaction rollback instance of PHP operation database

Source: Internet
Author: User
Tags php database
This article mainly introduced the PHP transaction rollback simple implementation method, combined with the instance form analysis PHP transaction definition, the submission and the rollback transaction concrete operation skill, needs the friend to consult. We hope to help you.

Specific 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 transaction      $conn->begintransaction ();      $conn->exec (' INSERT into ' hello ' (' FirstName ', ' LastName ', ' email ') VALUES (' YE ', ' xiaming ', ' 1111@163.com ') ");      $conn->exec (' INSERT into ' hello ' (' FirstName ', ' LastName ', ' email ') VALUES (' YE ', ' CONG ', ' 2222@163.com ') ");      $conn->exec (' INSERT into ' hello ' (' FirstName ', ' LastName ', ' email ') VALUES (' FANG ', ' MENG ', ' 3333@163.com ') ");      Commit TRANSACTION      $conn->commit ();      echo "New Records created successfully!";} catch (Pdoexception $e) {       //ROLLBACK TRANSACTION       $conn->rollback ();       echo $sql. " <br> ". $e->getmessage ();} $conn =null;

Related recommendations:

PHP database development Three points you need to know.

PHP's detailed PDO

Introduction to the functional operation of the PDO data Access abstraction layer in PHP

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.