Php transaction processing instance details, php transaction processing details

Source: Internet
Author: User
Tags mysql functions php development environment php mysql php template smarty template

Php transaction processing instance details, php transaction processing details

I. php transaction processing Overview:

Transaction: a collection of several events
Transaction Processing: When all events are successfully executed, the transaction is executed. If any event cannot be successfully executed, other events of the transaction will not be executed.

As long as your MySQL version supports the BDB or InnoDB table type, your MySQL has the ability to process transactions. HereMost InnoDB table types are usedAlthough there was something unpleasant about MySQL, such as Oracle's acquisition of InnoDB, this type of business event was not related to technology. The following takes the InnoDB table type as an example to briefly describe the transaction processing in MySQL.

Ii. 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 the exception handling mode $ pdo-> setAttribute (PDO: ATTR_AUTOCOMMIT, 0); // disable automatic submission} catch (PDOException $ e) {echo "database connection failed "; exit;} try {$ age = 10; $ pdo-> beginTransaction (); // start the 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 '"); // modify it to make the execution successful or fail at will/* if ($ affected_rows1 & $ affected_rows2) {$ pdo-> commit (); echo "operation successful ";} else {$ pdo-> rollback ();} */if (! $ Affected_rows1) throw new PDOException ("add error"); if (! $ Affected_rows2) throw new PDOException ("reduce error"); echo "operation successful"; $ pdo-> commit (); // if the first two updated SQL statements are successfully executed, the entire transaction is successfully executed} catch (PDOException $ e) {echo "operation failed :". $ e-> getMessage (); $ pdo-> rollback (); // An error occurred while executing the statement in the transaction. The entire transaction is canceled.} $ pdo-> setAttribute (PDO :: ATTR_AUTOCOMMIT, 1); // test whether echo is successful "\ n operation result: \ n"; $ SQL = "select * from kfry "; $ result = $ pdo-> query ($ SQL); foreach ($ result as $ v) {echo $ v ['k _ name']. "". $ v ['k _ age']. "\ n "; }?>

How does PHP handle SQL transactions?

There is transaction processing in EC. I have never studied how to implement PHP. I will tell you how to study it at home.
 
Php leveling procedure

The first stage is the introduction of basic WEB 1.1 website knowledge; 1.2 introduction to network protocols; 1.3 differences between B/S and C/S structures; and 1.4 introduction to WEB programming and website development technologies. Lecture 2: Webpage Design 2.1 Dreamweaver introduction and use; 2.2 static webpage HTML language; 2.3 title and paragraph, line feed and split line; 2.4 table and form; 2.5 frame, hyperlink, and image. Example: 1. Use tables for webpage layout design; 2. Use forms, tables, and frameworks for system background interface design. Third, the concept and basic syntax of DIV + CSS 3.1 CSS; 3.2 using CSS to set Rich Text effects to set image effects; 3.3 using CSS to set the style of tables and forms, set page and browser elements with CSS; 3.4 CSS box model; 3.7 CSS + DIV layout; CSS + DIV beautification and layout practices. Example: 1. Use DIV + CSS to design buttons and tabs; 2. Use DIV + CSS to design navigation menus; 3. Use DIV + CSS to design Forum webpages; 4, use DIV + CSS to design blog webpages. Fourth, PHP development environment 4.1 integrated development environment XAMPP installation; 4.2 Zend Studio installation and configuration; 4.3 Eclipse PDT installation and configuration; 4.4 compiling the first PHP program; 4.5 debug the PHP program. Fifth, PHP programming basics 5.1 PHP language features and development trends; 5.2 PHP variable constant data types; 5.3 PHP operators and expressions; 5.4 PHP process control statements; 5.5 PHP functions. Lecture 6: MySQL development basics 6.1 Introduction and installation of MySQL database system; 6.2 introduction to MySQL data types; 6.3 creation, modification and deletion of MySQL tables; and 6.4 MySQL query statements; 6.5 PHP MySQL Functions. Example: 1. Forum database table design; 2. PHP connects to the MySQL database for addition, deletion, modification, and query. Lecture 7: Introduction to Web 7.1 Development Technology Ajax 7.2 JavaScript; 7.3 JavaScript syntax basics; 7.4 DOM object basics and events; 7.5 explanation of Ajax core object XMLHttpRequest; Ajax asynchronous communication principles; 7.6 development of Ajax applications; 7.6 introduction and use of Ajax framework jQuery. Example: 1. Dynamic switch of the Tab; 2. Use Ajax in the forum system to verify whether the user name is registered; 3. Use Ajax in the forum system to obtain user information. Eighth, PHP 8.1 web site instances develop 8.2 web-style forum system development; web-style Blog system development. Example: 1. Integrate DIV + CSS + PHP + MySQL + Ajax technology development forum; 2. Develop a blog System Based on DIV + CSS + PHP + MySQL + Ajax technology. In the second stage, I will talk about object-oriented PHP 1.1 Introduction to object-oriented programming; 1.2 differences between process-oriented and object-oriented; 1.3 Basic Features of object-oriented; 1.4 categories, attributes, and methods; 1.5 constructors; 1.6 class instantiation; 1.7 class attributes and methods used; 1.8 class access control; 1.9 class inheritance and polymorphism; 1.10 object-oriented interfaces and abstract classes; 1.11 relationships between classes, objects, and objects; 1.12 common operators and keywords. Example: 1. Shopping Cart object relation design; 2. Class, student, course, and examination object relation design. Second, PHP template technology Smarty framework 2.1 Smarty template technology introduction; 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>
 

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.