doushou8299 2014-08-26 06:58
浏览 42
已采纳

SQL Codeigniter:从控制器创建保存点并回滚到保存点/回滚多个事务

I have processing db transaction from page using ajax request if user don't press submit button than roll-back all sql transaction which is done by ajax request (i will manage this but currently following logic not working if refresh current page).

I have try following code but not working,

function viewPage(){
   $needRollBack=$this->session->userdata('needRollBack');
   if($needRollBack){
      $this->db->trans_rollback();
   }
   $this->db->trans_begin();
   $this->MyModel1->insert(.....);
   $this->MyModel2->insert(.....);
.........................
}

function submitDetails(){
   $this->db->trans_complete();
   $this->session->set_userdata('needRollBack',false);
}

when again viewPage() function call or refresh page than if submitDetails() not called than rolleback all sql stransaction done via ajax request (starting point from trans_begin()) will be roll-baked? is this possible? Kindly guide me...

  • 写回答

1条回答 默认 最新

  • dsfd3546 2014-09-15 03:03
    关注

    There are a number of things that need addressing here.

    First would be that your database and schema type must support transactions (e.g. if you are using MyISAM table type in MySQL you will not be able to use transactions).

    Second to test whether or not transactions are succeeding in CI you write error messages to the error log if $this->db->trans_status() === false.

    Finally I would use an alternative approach to the one above (if possible) - one possible approach would be to store your data in a session (through the different stages) and make the call or multiple database calls at the final point (when user clicks submit). You can still use transactions this way and it simplifies the problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助