Home > php教程 > php手册 > php mysql 事务:php/ mysql 执行事务实例

php mysql 事务:php/ mysql 执行事务实例

WBOY
Release: 2016-06-21 08:51:44
Original
990 people have browsed it


近期项目软件升级到支持事务处理,做个示例供大家学习参考
环境 mysql 5.2 /php 5
支持事务的table 类型 需要innodb
$linkid =mysql_connect('localhost:3307','root',*******);
mysql_select_db('web_his',$linkid);
mysql_query("set names utf8");
/* 创建事务 */
mysql_query('start transaction') or exit(mysql_error());
$ssql1="insert into pf_item values('22','我们','30')"; //执行sql 1
if(!mysql_query($ssql1)){
echo $ssql1.mysql_errno().":".mysql_error()."
";
mysql_query('rollback') or exit(mysql_error());//判断当执行失败时回滚
exit;
}
$ssql1="insert into pf_item values('21','hell','10')"; //执行sql 2
if(!mysql_query($ssql1)){
echo $ssql1.mysql_errno().":".mysql_error()."
";
mysql_query('rollback') or exit(mysql_error());//判断当执行失败时回滚
exit;
}
mysql_query('commit') or exit(mysql_error());//执行事务
mysql_close($linkid);
?>

本文链接http://www.cxybl.com/html/wlbc/Php/20120531/27125.html



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template