search
Homephp教程php手册php+mysql事务rollback&commit示例

php+mysql事务rollback&commit示例

Jun 13, 2016 pm 12:19 PM
ampcommitmysqlphp+mysqlqueryaffairsstartExample

mysql_query("BEGIN");//开始一个事务
mysql_query("SET AUTOCOMMIT=0"); //设置事务不自动commit
$insert="INSERT INTO userinfo VALUES ('aa12','aa','1','aaa')";
mysql_query($insert);
mysql_query("COMMIT");//非autocommit模式,必须手动执行COMMIT使操作生效
//mysql_query("SET AUTOCOMMIT=0");
$insert="INSERT INTO userinfo VALUES ('aa20','aa','1','aaa')";
$insert="INSERT INTO userinfo VALUES ('aa8','aa','1')";
//mysql_query("COMMIT");
if(mysql_num_rows==0)
mysql_query("ROLLBACK");//非autocommit模式,执行ROLLBACK使事务操作无效
else echo "ok";
//mysql_query("CLOSE");
mysql_query("SET AUTOCOMMIT=1");//恢复autocommit模式
$insert="INSERT INTO userinfo VALUES ('aa15','aa','1','aaa')";
mysql_query($insert);//不需要手动执行COMMIT就可以使事务操作生效

执行BEGIN之后,其作用同set autocommit=0,而且之后设置set autocommit=0或1时无效。所以,为使操作清楚,一般不使用BEGIN。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools