//需要修改表引擎为innodb,myisam不支持事物
//alter table table_name engine=innodb;
<?php
public function index()
{
$this->db->trans_begin();
$this->db->query("update pdotest set name='songzhongji' where id='11'");
$row = $this->db->affected_rows();
echo $row;
//影响行数为0 ==》回滚
if($row == 0 )
{
$this->db->trans_rollback();
} else {
//不为0 ,修改成功,进行添加
//判断状态,添加成功,进行提交
$this->db->query("insert into pdotest(name,pwd) VALUES ('123','456')");
if ($this->db->trans_status() === FALSE)
{
$this->db->trans_rollback();
}
else
{
$this->db->trans_commit();
}
}
} pdo事物回滚
最新推荐文章于 2021-02-01 16:02:00 发布
9334

被折叠的 条评论
为什么被折叠?



