最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php事务回滚简单实现方法示例
时间:2022-06-24 14:43:53 编辑:袖梨 来源:一聚教程网
代码如下 | 复制代码 |
$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','[email protected]')" ); $conn -> exec ( "INSERT INTO `hello`(`firstname`,`lastname`,`email`)VALUES('YE','CONG','[email protected]')" ); $conn -> exec ( "INSERT INTO `hello`(`firstname`,`lastname`,`email`)VALUES('FANG','MENG','[email protected]')" ); //提交事务 $conn ->commit(); echo "New records created successfully!" ; //回滚事务 $conn ->rollBack(); echo $sql . " . $e ->getMessage(); } $conn =NULL; |
相关文章
- 光遇12.26免费魔法有什么 12-26
- 江南百景图碎金泉怎么样 12-26
- 江南百景图游宴廊怎么样 江南百景图游宴廊建筑介绍 12-26
- 江南百景图碎金泉怎么样 江南百景图碎金泉建筑介绍 12-26
- 炉石传说兑换码大全 12-26
- 重返未来1999趋光性研究夜幕之外怎么玩 趋光性夜幕之外活动介绍 12-26