最新下载
热门教程
- 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; | |
相关文章
- 基于Ollama本地搭建OpenClaw私人助手的实现方式步骤实用指南 10-03
- starwave:AI Agent 工具实践指南 10-03
- Paper2Seminar:AI Agent 工具实践指南 10-03
- PromptSkill4image:实践指南 10-03
- pishi-normalno:AI Agent 工具实践指南 10-03
- contract-review:实践指南 10-03