Adding transaction processing for MYSQL database _mysql

Source: Internet
Author: User
The statement is as follows: ALTER TABLE TableName ENGINE=INNODB;
The table to use
Copy Code code as follows:

CREATE TABLE IF not EXISTS ' test ' (
' ID ' int (a) not NULL auto_increment,
' Websitename ' varchar character set UTF8 not NULL,
' Websiteurl ' varchar character set UTF8 not NULL,
PRIMARY KEY (' id ')
) Engine=innodb DEFAULT Charset=utf8 auto_increment=1;

The second thing is if you add things:
Copy Code code as follows:

<?php
$con = mysql_connect ("localhost", "root", "Vertrigo");
Start a transaction
Mysql_db_query ("Mysqlnew", "BEGIN");
$INSERTSQL = "INSERT INTO Test (Websitename,websiteurl) VALUES (' cloud-dwelling community ', ' http://www.jb51.net ')";//The record is inserted into the database
Mysql_db_query ("Mysqlnew", $INSERTSQL);
$INSERTSQL = "INSERT INTO Test (Websitename,websiteurl) VALUES (' Baidu ', ' http://www.baidu.com ')";//The record is inserted into the database
Mysql_db_query ("Mysqlnew", $INSERTSQL);
Ending transaction transactions
Mysql_db_query ("Mysqlnew", "COMMIT");
Start a transaction
Mysql_db_query ("Mysqlnew", "BEGIN");
$INSERTSQL = "INSERT INTO Test (Websitename,websiteurl) VALUES (' Google ', ' http://www.google.com.hk ')";//The record is not inserted into the database
Mysql_db_query ("Mysqlnew", $INSERTSQL);
Ending transaction transactions
Mysql_db_query ("Mysqlnew", "ROLLBACK");
Start a transaction
Mysql_db_query ("Mysqlnew", "BEGIN");
$INSERTSQL = "INSERT INTO Test (Websitename,websiteurl) VALUES (' Bing ', ' http://www.bing.com ')";//The record is not inserted into the database
Mysql_db_query ("Mysqlnew", $INSERTSQL);
?>

Inserted data
ID Websitename websiteurl
1 cloud-dwelling community http://www.jb51.net
200 degrees Http://www.baidu.com

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.