Php implements mysql transaction processing method, phpmysql transaction processing _ PHP Tutorial

Source: Internet
Author: User
Php implements mysql transaction processing and phpmysql transaction processing. Php implements mysql transaction processing. phpmysql transaction processing this article describes how php implements mysql transaction processing. Share it with you for your reference. The specific analysis is as follows: to implement php to implement mysql transaction processing, phpmysql transaction processing

This example describes how to implement mysql transaction processing in php. Share it with you for your reference. The specific analysis is as follows:

To implement this function, the condition is that mysql 5.2/php 5 supports the transaction table type, and InnoDB is required. with these conditions, you can implement the above, this rollback operation is often used by large projects, such as banks and e-commerce. if you need it, please refer to it.

Recently, the project software has been upgraded to support transaction processing. An example is provided for your reference.

Environment mysql 5.2/php 5

InnoDB is required for table types that support transactions.

The php mysql transaction processing implementation program code is as follows:

The code is as follows:

<? PHP
$ LinkID = mysql_connect ('localhost: 100', 'root ',*******);
Mysql_select_db ('web _ his ', $ LinkID );
Mysql_query ("set names utf8 ");

/* Create a transaction */
Mysql_query ('Start transaction') or exit (mysql_error ());
$ Ssql1 = "insert into pf_item values ('22', 'Ours ', '30')"; // execute SQL 1
If (! Mysql_query ($ ssql1 )){
Echo $ ssql1.mysql _ errno (). ":". mysql_error ()."
";
Mysql_query ('rollback') or exit (mysql_error (); // determines whether to roll back when execution fails.
Exit;
}
$ Ssql1 = "insert into pf_item values ('21', 'hangel', '10')"; // execute SQL 2
If (! Mysql_query ($ ssql1 )){
Echo $ ssql1.mysql _ errno (). ":". mysql_error ()."
";
Mysql_query ('rollback') or exit (mysql_error (); // determines whether to roll back when execution fails.
Exit;
}

Mysql_query ('commit ') or exit (mysql_error (); // execute the transaction

Mysql_close ($ LinkID );
?>

I hope this article will help you with php programming.

Examples in this article describes how to implement mysql transaction processing in php. Share it with you for your reference. The specific analysis is as follows...

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.