Add a transaction processing method to the mysql database

Source: Internet
Author: User

Statement: alter table tableName engine = InnoDB;
Tables Used Copy codeThe Code is as follows: create table if not exists 'test '(
'Id' int (10) not null auto_increment,
'Websitename' varchar (200) character set utf8 not null,
'Websiteurl' varchar (200) character set utf8 not null,
Primary key ('id ')
) ENGINE = InnoDB default charset = utf8 AUTO_INCREMENT = 1;

The second is not to add things:Copy codeThe Code is as follows: <? Php
$ Con = mysql_connect ("localhost", "root", "vertrigo ");
// Start the transaction
Mysql_db_query ("mysqlnew", "BEGIN ");
$ InsertSql = "insert into test (websitename, websiteurl) values ('feet home', 'HTTP: // www.jb51.net ')"; // insert this record into the database
Mysql_db_query ("mysqlnew", $ insertSql );
$ InsertSql = "insert into test (websitename, websiteurl) values ('Baidu ', 'HTTP: // www.baidu.com')"; // insert this record into the database
Mysql_db_query ("mysqlnew", $ insertSql );
// End the transaction
Mysql_db_query ("mysqlnew", "COMMIT ");
// Start the transaction
Mysql_db_query ("mysqlnew", "BEGIN ");
$ InsertSql = "insert into test (websitename, websiteurl) values ('Google ', 'HTTP: // www.google.com.hk')"; // This record is not inserted into the database
Mysql_db_query ("mysqlnew", $ insertSql );
// End the transaction
Mysql_db_query ("mysqlnew", "ROLLBACK ");
// Start the transaction
Mysql_db_query ("mysqlnew", "BEGIN ");
$ InsertSql = "insert into test (websitename, websiteurl) values ('bing ', 'HTTP: // www.bing.com')"; // This record is not inserted into the database
Mysql_db_query ("mysqlnew", $ insertSql );
?>

Inserted data
Id websitename websiteurl
1 foot home http://www.jb51.net
2 Baidu Co., 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.