douzhu1188 2017-09-12 05:57
浏览 132

函数恢复mysql语句

How can I implement a undo changes function in my php application, so if the user for example added a new member to a group, or deleted item a notification message will appear: The selected item have been deleted, undo delete action(link that trigger the undo function).

The following is a working code:

public function deleteRecord($id) {
            $group = $this->query('SET autocommit=0');
            $group = $this->query('DELETE FROM  `members` WHERE memberID = '.$id.'');

    }


    public function undo_delete() {
            $member = $this->query('rollback');
    if($member) {
            trigger_error('Undo action has been completed. ', E_USER_NOTICE);
            return true;
}

    }

The only problem with this code is the transaction has not been submitted, so rollback or log out will undo all the changes that has been done during the user session, I am not sure if this is the best approach to create a redo function, any suggestions?

  • 写回答

2条回答 默认 最新

  • duanmu0834 2017-09-12 06:25
    关注

    You will not be able to undo with 2 different requests .Because when you will call the undo . It will undo all delete happened for all the members . To solve it I would suggest -

    1. You create a new table where you keep the information of the deleted record, eg- deleted_members.
    2. When user calls for undo fetch the data from the deleted_members table and insert into original members table.
    3. After successful insert in original table ,remove the data from the delete information table.

    I hope this helped.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?