Transaction processing analysis of PDO in PHP, PHPPDO transaction _php Tutorial

Source: Internet
Author: User
Tags php database

Transaction processing analysis of PDO in PHP, PHPPDO transaction processing


This paper analyzes the transaction processing of PDO in PHP. Share to everyone for your reference, as follows:

Transaction processing has four properties: atomicity, consistency, independence, persistence.

Not all databases support transactional processing, and PDO provides transactional support for databases that can perform transactional processing.

The configuration transaction should be aware of:

1. Close the automatic submission of PDO;

$pdo->setattribute (Pdo::attr_autocommit, false);

2, open a business need method;

$pdo->begintransaction (); Open a transaction $pdo->commit (); Commit Transaction $pdo->rollback (); Rolling back a transaction

3, the general transaction processing is running in Try...catch ... Statement, the catch code snippet is executed when the transaction fails.

<?phptry {  $pdo->begintransaction ();//Open a transaction  $row = null;  $row = $pdo->exec ("xxx"); Executes the first SQL  if (! $row)    throw new pdoexception (' hint message or execute action '),//If the exception prompt message or perform action  $row = $pdo->exec ("xxx"); Executes the second SQL  if (! $row)    throw new pdoexception (' hint message or execute action ');  $pdo->commit ();} catch (Pdoexception $e) {  $pdo->rollback ();//execution failed, transaction rollback  exit ($e->getmessage ());}? >

In the case of SQL statements in a transaction, all SQL is not executed if an error occurs. Execution is only committed when all SQL is correct.

More interested in PHP related content readers can view the topic: "PHP based on PDO Operation Database Skills summary", "PHP operation and operator Usage Summary", "PHP Network Programming Tips", "PHP Basic Grammar Primer Tutorial", "PHP operation Office Document Tips Summary ( including word,excel,access,ppt), PHP date and Time usage summary, PHP Primer for object-oriented programming, PHP string usage Summary, PHP+MYSQL database Operations Starter Tutorial, and A summary of common PHP database operation techniques

I hope this article is helpful to you in PHP programming.

Articles you may be interested in:

    • Some additions to the problem of solving Chinese garbled in the PDO in PHP
    • PHP PDO Chinese garbled solution
    • Analysis of Common library examples of PDO in PHP
    • Simple example of the PDO operation in PHP
    • A simple way to use PDO in PHP5.2
    • The method of PDO in PHP to realize the deletion and modification of database
    • MySQL connection in PHP using PDO details
    • Database connection in PHP comparison of PDO and mysqli
    • List of output results of various parameters of PHP PDO fetch mode
    • PHP using the PDO method
    • PHP using PDO to manipulate the database garbled problem solving method

http://www.bkjia.com/PHPjc/1119988.html www.bkjia.com true http://www.bkjia.com/PHPjc/1119988.html techarticle The transaction processing analysis of PDO in PHP, PHPPDO transaction Processing This paper analyzes the transaction of PDO in PHP. Share to everyone for your reference, as follows: Transaction processing has four features: ...

  • Related Article

    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.