MySQL thing implementation syntax
1) Begin SQL statement rollback or commit
START TRANSACTION SQL statement rollback or commit
2) Modify the #本文未涉及 that the autocommit auto-commit is turned on
Personal understanding of this logic
Start things
Submit each SQL, and record the success or not of the submission
Make judgments on all SQL submission results
Is successful, commit# commits the transaction, and all operations are performed
Otherwise (any one execution fails), then rollback. To perform a transaction rollback
The test table structure and PHP code are attached below
Table structure
CREATE TABLE ' test01 ' (
The ' # ' varchar (+) DEFAULT NULL,
' * ' varchar (+) DEFAULT NULL
) Engine=innodb DEFAULT Charset=utf8
PHP code
<?
$lnk = mysql_connect ("localhost", "root", "");
mysql_select_db ("test");
mysql_query ("BEGIN");
mysql_query ("START TRANSACTION");
$query = mysql_query ("Update test01 set ' 01 ' = 12");
$q 1 = mysql_error ();
if ($q 1) {
echo "$q 1". " \ n ";
}
$query = mysql_query ("Update test01 set ' 02 ' = 3");
$q 2 = mysql_error ();
if ($q 2) {
echo "$q 2". " \ n ";
}
if (! $q 1 &&! $q 2) {
mysql_query ("COMMIT"); All successful, submit execution results
echo "Commit". " \ n ";
} else {
mysql_query ("ROLLBACK"); Any error occurred, rollback and cancel execution result
echo "rollback". " \ n ";
}
Var_dump ($q 1, $q 2);
Mysql_close ($lnk);
?>
Modify the SQL statement so that an execution SQL error occurs and the test results
This article references: http://www.111cn.net/database/mysql/53781.htm
Http://www.cnblogs.com/in-loading/archive/2012/02/21/2361702.html
Thank you very much, author!
MySQL things implement approximate logic test