PHP transaction examples, a detailed explanation of PHP transaction processing
First, PHP transaction processing Overview:
Transaction: is a collection of several events
Transaction processing: When all events execute successfully, the transaction executes, and if any of the events fail to execute successfully, the other events of the transaction are not executed.
As long as your MySQL version supports BDB or InnoDB table types, your MySQL has the ability to handle transactions. In this, but also with the InnoDB table type of the most , although later, such as Oracle acquisition InnoDB and other things that make MySQL uncomfortable, but this kind of business events and technology-independent, the following is a InnoDB table type as an example of the transaction processing in MySQL.
Second, the PHP transaction processing code:
<?php try{$pdo =new PDO ("Mysql:host=localhost;dbname=psp", "Root", ""); $pdo->exec ("Set names UTF8"); $pdo->setattribute (pdo::attr_errmode,pdo::errmode_exception);//Set exception handling mode $pdo->setattribute (pdo::attr_ autocommit,0);//Close autocommit}catch (pdoexception $e) {echo "database connection failed"; exit; try{$age =10; $pdo->begintransaction ();// Start transaction $affected _rows1= $pdo->exec ("Update kfry set k_age=k_age+{$age} where k_name= ' User1 '"); $affected _rows2= $pdo->exec ("Update kfry set k_age=k_age-{$age} where k_name= ' User2 '");//arbitrarily change to make it perform successfully or fail */if ($ affected_rows1&& $affected _rows2) {$pdo->commit (); Echo "Operation succeeded"; }else{$pdo->rollback ();} */if (! $affected _rows1) throw new Pdoexception ("Add error"); if (! $affected _rows2) throw new Pdoexception ("reduce error"); Echo "Operation succeeded"; $pdo->commit ();//If execution succeeds to the previous two update SQL statements, the entire transaction executes successfully}catch (Pdoexception $e) {echo "Operation failed:". $e->getmessage (); $ Pdo->rollback ();//The statement in the execution transaction is out of the question, the whole transaction is revoked} $pdo->setattribute (pdo::attr_autocommit,1); Whether the test was successful echo "\ nthe operation result is: \ n";$sql = "SELECT * from Kfry"; $result = $pdo->query ($sql); foreach ($result as $v) {echo $v [' K_name ']. " ". $v [' K_age ']." \ n "; }?>
How does PHP typically do SQL transactions?
There are transactions in EC, PHP how to implement this has not been studied, home research and research to tell you
PHP Practice Steps
First stage first, the basic knowledge of Web Basic 1.1 website, 1.2 Network protocol Introduction, 1.3 B/S and C/s structure difference; 1.4 Web programming, Website development Technology Introduction. Second, web Design 2.1 dreamweaver introduction and use; 2.2 Static Web page HTML language; 2.3 headings and paragraphs, line breaks and splits, 2.4 forms, forms, 2.5 frames, hyperlinks, pictures. Example: 1, using a table for page layout design, 2, using forms, tables, frames for the system background interface design. The third, DIV+CSS 3.1 The concept of CSS and basic grammar; 3.2 Set the picture effect with the rich text effect of CSS, 3.3 set the style of table and form with CSS, set the elements of page and browser with CSS, 3.4 css box model; 3.7 css+div layout, css+ Div Landscaping and layout combat. Example: 1, use DIV+CSS Design button and tab, 2, use DIV+CSS to design navigation menu, 3, use DIV+CSS Design Forum webpage, 4, use DIV+CSS Design blog page. Four, PHP development Environment 4.1 Integrated development Environment XAMPP installation, 4.2 Zend Studio installation, configuration, 4.3 Eclipse PDT Installation and configuration, 4.4 write the first PHP program, 4.5 debug PHP program. The PHP Programming Foundation 5.1 PHP language features and development trend, 5.2 PHP variable constant data type, 5.3 php operator and expression, 5.4 php flow control statement; 5.5 PHP function. Six, MySQL Development Foundation 6.1 MySQL Database system introduction and installation; 6.2 MySQL data type introduction, 6.3 MySQL table creation, modification and deletion; 6.4 MySQL query statement; 6.5 PHP MySQL function is used in detail. Example: 1, Forum database table design; 2,php connection MySQL database, to achieve additions and deletions to check. Seventh, Web2.0 development Technology AJAX 7.1 JavaScript Introduction, 7.2 JavaScript Syntax Foundation, 7.3 DOM Object Foundation and events; 7.4 Ajax core Object XMLHttpRequest detailed; 7.5 Ajax asynchronous Communication principle ; 7.6 developing AJAX applications; 7.6 Ajax framework jquery Introduction and use. Example: 1,tab dynamic Switching effect, 2, the forum system using Ajax method to verify whether the user name is registered, 3, the forum system through the Ajax way to obtain user information. Eighth, PHP Web2.0 website Instance Development 8.1 Web2.0 Style forum system development8.2 Web2.0 style of blog system Combat Development. Example: 1, integrated DIV+CSS +php+mysql+ajax Technology Development Forum, 2, integrated DIV+CSS +php+mysql+ajax Technology Development Blog system. In the second stage, PHP object-oriented 1.1 object-oriented programming introduction, 1.2-oriented process and object-oriented differences, 1.3 object-oriented basic features, 1.4 classes, properties and methods, 1.5 constructors, 1.6 classes of instantiation, 1.7 use class properties and methods, 1.8 class of access control; 1 . Class 9 inheritance and polymorphism, 1.10 object-oriented interfaces and abstract classes, 1.11 classes, objects, and relationships between objects; 1.12 Several common operators and keywords. Example: 1, Shopping cart object relationship design, 2, class, students, curriculum, test object relationship design. Second, PHP template Technology Smarty Framework 2.1 Smarty Template technology, 2.2 Smarty installation and configuration, 2.3 Smarty variables and variable modifiers; 2.4 Smarty branch structure; 2.5 Smarty loop ... Remaining full text >>
http://www.bkjia.com/PHPjc/840632.html www.bkjia.com true http://www.bkjia.com/PHPjc/840632.html techarticle PHP transaction Examples, a detailed description of the PHP transaction, PHP Transaction Overview: Transaction: Is a collection of several events transaction processing: When all events executed successfully, the transaction is executed;