MySQL things implement approximate logic test

Source: Internet
Author: User
Tags sql error

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

Related Article

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.