doucheng4660 2009-06-01 10:22
浏览 61

有可能用PHP做mysql数据库事务和回滚吗?

example: making a payment transfer from user A to user B. Account of user A: -10 USD Account of user B: +10 USD

if there is an transaction, and something goes wrong, everything gets undone. So with transactions it will not happen that account of user A gets decreased by 10, while account of user B does not get increased by 10.

I know the java people make use of transactions and rollbacks all over the place. But I've never heard of PHP-guys doing that.

  • 写回答

2条回答 默认 最新

  • douxiajia6309 2009-06-01 10:27
    关注
    $db = new mysqli("localhost", "", "", "");
    $db->autocommit(FALSE);
    if ($db->query("INSERT ..."))
        $db->commit();
    else
        $db->rollback();
    

    Make sure your tables use InnoDB engine: MyISAM does not support transactions.

    Comment update:

    InnoDB is one of two major storage engines used by MySQL, the other one being MyISAM.

    MySQL comes with InnoDB support compiled in by default and in fact it takes some effort to disable it.

    I've never heard of MySQL with InnoDB disabled even by cheapest of the hosters.

    评论

报告相同问题?

悬赏问题

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