为mysql数据库添加添加事务处理的方法_MySQL
程序员文章站
2022-05-30 11:38:20
...
bitsCN.com
语句如下:alter table tableName engine=InnoDB;
用到的表
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 ;
第二不就是如果和添加事物:
$con = mysql_connect("localhost", "root", "vertrigo");
//开始事务
mysql_db_query("mysqlnew","BEGIN");
$insertSql ="insert into test(websitename,websiteurl)values('','http://www.bitsCN.com')";//该记录插入数据库
mysql_db_query("mysqlnew",$insertSql);
$insertSql ="insert into test(websitename,websiteurl)values('百度','http://www.baidu.com')";//该记录插入数据库
mysql_db_query("mysqlnew",$insertSql);
//结束事务事务
mysql_db_query("mysqlnew","COMMIT");
//开始事务
mysql_db_query("mysqlnew","BEGIN");
$insertSql ="insert into test(websitename,websiteurl)values('google','http://www.google.com.hk')";//该记录不插入数据库
mysql_db_query("mysqlnew",$insertSql);
//结束事务事务
mysql_db_query("mysqlnew","ROLLBACK");
//开始事务
mysql_db_query("mysqlnew","BEGIN");
$insertSql ="insert into test(websitename,websiteurl)values('bing','http://www.bing.com')";//该记录不插入数据库
mysql_db_query("mysqlnew",$insertSql);
?>
插入的数据
id websitename websiteurl
1 http://www.bitsCN.com
2 百度 http://www.baidu.combitsCN.com
用到的表
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 ;
第二不就是如果和添加事物:
$con = mysql_connect("localhost", "root", "vertrigo");
//开始事务
mysql_db_query("mysqlnew","BEGIN");
$insertSql ="insert into test(websitename,websiteurl)values('','http://www.bitsCN.com')";//该记录插入数据库
mysql_db_query("mysqlnew",$insertSql);
$insertSql ="insert into test(websitename,websiteurl)values('百度','http://www.baidu.com')";//该记录插入数据库
mysql_db_query("mysqlnew",$insertSql);
//结束事务事务
mysql_db_query("mysqlnew","COMMIT");
//开始事务
mysql_db_query("mysqlnew","BEGIN");
$insertSql ="insert into test(websitename,websiteurl)values('google','http://www.google.com.hk')";//该记录不插入数据库
mysql_db_query("mysqlnew",$insertSql);
//结束事务事务
mysql_db_query("mysqlnew","ROLLBACK");
//开始事务
mysql_db_query("mysqlnew","BEGIN");
$insertSql ="insert into test(websitename,websiteurl)values('bing','http://www.bing.com')";//该记录不插入数据库
mysql_db_query("mysqlnew",$insertSql);
?>
插入的数据
id websitename websiteurl
1 http://www.bitsCN.com
2 百度 http://www.baidu.combitsCN.com
上一篇: php socket讲解与实例
下一篇: 发现一个有趣的小东西请问原理