duanlou2917 2016-10-11 19:16
浏览 111
已采纳

在php中阻止数据库提交断言失败

For the sanity testing of my code I am putting asserts at various places in my code.

I want it to be the case that whenever an assert is hit, the database transaction should not be completed (i.e. the data should not be committed to database, instead it should be rolled back).

I could not find any clean way of achieving this.

I am using the code igniter framework.

Any idea how to achieve this?

  • 写回答

1条回答 默认 最新

  • duangu8264 2016-10-13 04:49
    关注

    The functionality should not be part of an assert. If it is the case then the functionality will be distorted in production mode when asserts are disabled.

    We can perform additional database operation on assert failure to record and track more details of the error, but should not abort/interfere with outside transactions.

    Assertions should be used as a debugging feature only. You may use them for sanity-checks that test for conditions that should always be TRUE and that indicate some programming errors if not or to check for the presence of certain features like extension functions or certain system limits and features.

    Assertions should not be used for normal runtime operations like input parameter checks. As a rule of thumb your code should always be able to work correctly if assertion checking is not activated.

    More details

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

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改