mysql事务回滚实例
2014-11-20 11:12
585 查看
预排序遍历树,当子节点插入数据失败时,需要进行回滚。
M层://新加 function add_projKind($gongchengjianming,$level,$qishijuli,$wdate,$beizhu){ //$query = $this->db->query("select * from student"); //$return['boolean'] = FALSE; $this->db->query("set autocommit=0"); $this->db->query("begin;"); $query = $this->db->query("select * from constrproj"); $result_count = count($query->result()); $result_count2 = 0; if($result_count==0){ //$return['boolean'] = TRUE; $this->db->query("insert constrproj (ConstrProjName,CPKind,Mileage,ProjStart,ProjNote,PLeft,PRight,KindLvl) values('$gongchengjianming','$level','$qishijuli','$wdate','$beizhu',1,2,0) " ); $this->db->query("insert constrprojact (ConstrProjACTName,CPKind,Mileage,ProjStart,ProjNote,PLeft,PRight,KindLvl) values('$gongchengjianming','$level','$qishijuli','$wdate','$beizhu',1,2,0) " ); $query2 = $this->db->query("select * from constrproj"); $result_count2 = count($query2->result()); }else{ $this->db->query("select @myLeft:=PLeft from constrproj where ConstrProjID = (select max(ConstrProjID) from constrproj)"); $this->db->query("UPDATE constrproj SET PRight = PRight + 2 WHERE PRight > @myLeft"); $this->db->query("UPDATE constrproj SET PLeft = PLeft + 2 WHERE PLeft > @myLeft"); $this->db->query("INSERT INTO constrproj(ConstrProjName, PLeft, PRight) VALUES('$gongchengjianming', @myLeft + 1, @myLeft +2)" ); $query2 = $this->db->query("select * from constrproj"); $result_count2 = count($query2->result()); } if($result_count<>$result_count2){ $message = "创建建名工程成功!"; $this->db->query("set autocommit=1"); $return['boolean'] = TRUE; $return['message'] = $message; return $return; }else{ $message = "创建建名工程失败!"; $this->db->query("rollback"); $this->db->query("set autocommit=1"); $return['boolean'] = FALSE; $return['message'] = $message; return $return; } }
C层及显示
前台显示
function add_jianming(){ $gongchengjianming =trim($this->input->post('gongchengjianming')); $level =trim($this->input->post('level')); $qishijuli =trim($this->input->post('qishijuli')); $wdate =trim($this->input->post('wdate')); $beizhu =trim($this->input->post('beizhu')); //echo $beizhu; //die(); $this->load->model('project_m'); $return = $this->project_m->add_projKind($gongchengjianming,$level,$qishijuli,$wdate,$beizhu); <span style="background-color: rgb(255, 102, 102);">if($return['boolean']){ echo '<script>alert("'.$return['message'].'");location.href="'.base_url().'project/projectName";</script>'; }else{ echo '<script>alert("'.$return['message'].'");location.href="'.base_url().'project/projectName";</script>'; }</span> }
相关文章推荐
- 解析php mysql 事务处理回滚操作(附实例)
- mysql实现事务的提交和回滚实例
- mysql实现事务的提交和回滚实例
- 解析php mysql 事务处理回滚操作(附实例)
- 解析php mysql 事务处理回滚操作(附实例)
- 解析php mysql 事务处理回滚操作(附实例)
- 解析php mysql 事务处理回滚操作
- mysql 事务应用实例
- sql事务(Transaction)用法介绍及回滚实例
- spring + hibernate + mysql 事务不回滚
- PHP mysql 事务处理实例
- 【MySQL】MySQL事务回滚脚本
- php/ mysql 执行事务实例
- 在Mysql存储过程中使用事务实例
- MYSQL事务回滚的2个问题分析
- [转] C# mysql 事务回滚
- 网站建设PHP mysql 事务处理实例
- (MySQL)Spring3+Mybatis3使用注解式事务声明(@Transactional)无法回滚
- sql事务(Transaction)用法介绍及回滚实例
- 存储过程事务 用事务点处理回滚实例