使用PDO自动提交 [英] Autocommit with PDO

查看:86
本文介绍了使用PDO自动提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的交易无法回滚. 如何使用PDO(我拥有InnoDB 5.7.18)在php脚本中将autocommit设置为false(或0)?

The rollback of my transaction doesn't work. How do I set autocommit to false (or 0) in the php script using PDO (I have InnoDB 5.7.18) ?

这是我的代码:

     global $bdd;  //defined with PDO

       try {                             
            $bdd->beginTransaction();
            /* my requests */
            $bdd->commit();
        } catch (Exception $e) {
            $bdd->rollBack();
            return $e->getMessage();
        }

        return true;
    }

推荐答案

我自己解决了问题:我的一些表在MyISAM中(而大多数表在InnoDB中->我正在使用旧的数据库系统... );因此回滚不适用于这些表.一旦将它们更改为InnoDB,它就会起作用. 感谢大家的帮助!

I solved my problem myself: a few of my tables were in MyISAM (whereas the majority are in InnoDB -> I work with an old database system...); so the rollback didn't work for these tables. Once I changed them into InnoDB, it worked. Thanks to everybody for the help !

这篇关于使用PDO自动提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆