a while ago I completely recoded my application so that MySQL would perform in an ACID way.

不久之前,我完全重新编写了我的应用程序,以便MySQL以ACID方式执行。

At the very top level of all functions I do something like this:

在所有功能的最顶层我做这样的事情:

        try{
            $db->begin();
            dosomething($_SESSION['userid']);
            $db->commit();
        }catch(advException $e){
            $eCode = $e->getCode();
            $eMessage = $e->getMessage();
            # Success
            if ($eCode == 0){
                $db->commit();
            }else{
                $db->rollback();
            }
        }

Within the function 'dosomething' I have the Exceptions thrown to users like:

在函数'dosomething'中,我向用户抛出了例外:

throw new Exception('There was a problem.',1);

or

要么

throw new Exception('You have successfully done that!', 0);

So that I can control the flow of the program. If theres a problem then roll back everything that happened and if everything was good then commit it. It's all worked quite great but there's just one flaw that I've come across so far. I added Exception logging so I can see when there are issues that users face. But the problem is, if the table that logs the errors is InnoDB then it's also included in the transaction and will rollback if theres a problem so no errors are stored. To get around this I basically just made the Error logging table MyISAM so when a rollback is done, the changes are still there.

这样我就可以控制程序的流程。如果这是一个问题然后回滚发生的一切,如果一切都很好,然后提交它。这一切都很有效,但到目前为止我遇到的只有一个漏洞。我添加了异常日志记录,因此我可以看到用户遇到的问题。但问题是,如果记录错误的表是InnoDB,那么它也包含在事务中,并且如果存在问题则将回滚,因此不会存储错误。为了解决这个问题,我基本上只是创建了错误记录表MyISAM,因此当回滚完成时,更改仍然存在。

Now I'm thinking of other bits I'd like to keep out of the transaction, like sending a mail within my application to the admin to help alert of problems.

现在我正在考虑其他一些我想要避开的事务,比如在我的应用程序中向管理员发送邮件以帮助提醒问题。

Is there any sort of way for me to not include a database insert within the parent transaction? Have I taken a bad route in terms of Application/DB design and is there any other way I could have handled this?

我有没有办法在父事务中不包含数据库插入?我是否在应用程序/数据库设计方面采取了不好的方法,还有其他方法可以解决这个问题吗?

Thanks, Dominic

谢谢,多米尼克

2 个解决方案

#1


3

It is not good idea to throw an Exception on success.

成功抛出异常并不是一个好主意。

You have to do DB insert after previous rollback was called.

在调用上一次回滚后,您必须执行数据库插入。

catch (Exception $e) {
  $db->rollback();
  Log::insert('Error: ' . $e->getMessage());
}

Try to use Logger to control your program. It is more flexible way.

尝试使用Logger来控制您的程序。这是更灵活的方式。

更多相关文章

  1. You can't specify target table 'compares' for up
  2. 【错误】:MySql Host is blocked because of many connection err
  3. mysql 服务意外停止1067错误解决办法小结
  4. 求问vs窗体应用程序用gridview连接mysql未能获取数据库对象的列
  5. Ruby 1.9 + MySQL中发生访问错误
  6. 错误'未知表引擎'InnoDB''查询。重启mysql后
  7. MySQL“在建立到SQL Server的连接时发生与网络相关或特定于实例
  8. Android应用程序与外部数据库之间的安全性
  9. 尝试将纬度和经度发布到数据库时,Android JSON解析错误

随机推荐

  1. 格式化聊天列表时间
  2. PHP的防御XSS注入的终极解决方案
  3. 关于PHP Shell_exec所遇到的坑
  4. PHP如何获取不带命名空间的类名
  5. 解决PHP中Web程序中shell_exec()执行Shel
  6. PHP如何下载远程文件到指定目录
  7. PHP执行Linux命令的两个有用的函数exec和
  8. php中关于isset()、isnull()和empty()的
  9. php实现利用expat方式解析xml文件
  10. curl提交json数据的方法