无法在Zend Framework中回滚事务 [英] Cannot rollback transaction in Zend Framework

查看:87
本文介绍了无法在Zend Framework中回滚事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Zend Framework中使用以下代码进行事务处理,但是回滚功能不起作用(数据通过insertSome($ data)插入数据库中). 怎么了?

I use the following code for transaction in Zend Framework but the rollback function doesn't work (Data is inserted into the database by insertSome($data)). What's wrong?

            $db->beginTransaction();
            try{
               $model->insertSome($data);
               $model->insertAll($data2); //this line cannot be run and the whole transaction should be rolled back.
               $db->commit();
            } catch (Exception $e) {
                $db->rollBack();
                echo $e->getMessage();
            }

推荐答案

除非有至少一个带有否决权的答案,否则我们不会从StackOverflow的未回答"问题列表中找到此问题.因此,我将重复您上面在评论中讨论的解决方案.

We can't get this question out of the list of "unanswered" questions on StackOverflow unless there is at least one answer with an upvote. So I'm repeating the solution you discussed above in the comments.

@nos建议:

MySQL是否偶然使用您的数据库? MyISAM表?他们不支持 交易.您必须使用InnoDB 表,如果你想交易 支持.

Is your DB by any chance MySQL using MyISAM tables ? They don't support transactions. You'd have to use InnoDB tables if you want transaction support.

@Billy回复:

是的,我正在使用MyISAM表.我已经更改为InnoDB表,并且可以使用.谢谢.

Yes, I am using MyISAM tables. I have changed to InnoDB tables and it works. Thanks.

(我将其标记为社区Wiki答案,因此我没有从中获得任何要点.)

(I've marked this as a community wiki answer so I don't get any points from it.)

这篇关于无法在Zend Framework中回滚事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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