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