The default database engine of the mysql database is MyISAM, which does not support transactions. If you add a Data Execution statement, the singular value does not work, even if the transaction is rolled back, the record is inserted. The first step we need to do is to change the database engine.
The default database engine of the mysql database is MyISAM, which does not support transactions. If you add a Data Execution statement, the singular value does not work, even if the transaction is rolled back, the record is inserted. The first step we need to do is to change the database engine.
Statement: alter table tableName engine = InnoDB;
Tables Used
The 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:
The Code is as follows:
$ 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.