您好,欢迎访问一九零五行业门户网

php实现事务回滚的方法

这篇文章主要介绍了php事务回滚简单实现方法,结合实例形式分析了php事务的定义、提交及回滚事务的具体操作技巧,需要的朋友可以参考下
本文实例讲述了php事务回滚简单实现方法。分享给大家供大家参考,具体如下:
$servername="localhost"; $username="root"; $password="admin"; $dbname="test"; try{ $conn=new pdo("mysql:host=$servername;dbname=$dbname",$username,$password); $conn->setattribute(pdo::attr_errmode,pdo::errmode_exception); //开始事务 $conn->begintransaction(); $conn->exec("insert into `hello`(`firstname`,`lastname`,`email`)values('ye','xiaming','yexianming@163.com')"); $conn->exec("insert into `hello`(`firstname`,`lastname`,`email`)values('ye','cong','yecong@163.com')"); $conn->exec("insert into `hello`(`firstname`,`lastname`,`email`)values('fang','meng','fangmeng@168.com')"); //提交事务 $conn->commit(); echo "new records created successfully!"; }catch(pdoexception $e){ //回滚事务 $conn->rollback(); echo $sql."<br>".$e->getmessage(); } $conn=null;
以上就是本文的全部内容,希望对大家的学习有所帮助。
相关推荐:
thinkphp事务操作实例详解
php基于pdo的事务处理方法
thinkphp 3.2.2事务操作的方法
以上就是php实现事务回滚的方法的详细内容。
其它类似信息

推荐信息