pdo事物回滚

来源:互联网 发布:linux 读取文件末尾5行 编辑:程序博客网 时间:2024/05/04 05:32
//需要修改表引擎为innodb,myisam不支持事物//alter table table_name engine=innodb;<?phppublic 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();            }        }}

0 0