public function pdo(){ //开启事物 $this->db->trans_begin(); //执行修改 $this->db->query("update 表名 set name='1123'where id=1"); $rows=$this->db->affected_rows(); $this->db->query("insert into 表名(name) VALUES('asd')"); //如果 事物状态是false 或者 影响行数是0 则执行回滚 if($this->db->trans_status()===false ||$rows==0){ //执行回滚 $this->db->trans_rollback(); echo "正在回滚..."; }else{ //执行提交 修改 添加 $this->db->trans_commit(); echo "执行成功"; } }
PDO事务回滚
最新推荐文章于 2019-06-18 11:10:12 发布