交易回滚不起作用 [英] Transaction rollback doesn't work

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

问题描述

我已经在PDO系统周围制作了具有附加功能的数据库包装器(是的,我知道包装器周围的包装器,但是它只是具有某些附加功能的PDO).但是我注意到了一个问题.

I have made a database wrapper with extra functionality around the PDO system (yes, i know a wrapper around a wrapper, but it is just PDO with some extra functionality). But i have noticed a problem.

以下情况不起作用,应该是这样:

The folowing doesn't work like it should be:

<?php
var_dump($db->beginTransaction());

$db->query('
 INSERT INTO test
 (data) VALUES (?)
 ;',
 array(
  'Foo'
 )
);
print_r($db->query('
 SELECT *
 FROM test
 ;'
)->fetchAll());

var_dump($db->rollBack());

print_r($db->query('
 SELECT *
 FROM test
 ;'
)->fetchAll());
?>

var_dump显示出beginTransaction和rollBack函数返回true,因此没有错误.

The var_dump's shows that the beginTransaction and rollBack functions return true, so no errors.

我希望第一个print_r调用显示N个项目的数组,第二个调用显示N-1个项目.但这不是事实,它们都显示相同数量的项目.

I expected that the first print_r call show a array of N items and the second call show N-1 items. But that issn't true, they both show same number of items.

我的$ db-> query(< sql>,< values>)然后再调用$ pdo-> prepare(< sql>)-> execute(< values>)(带有额外的错误处理功能) ).

My $db->query(< sql >, < values >) call nothing else then $pdo->prepare(< sql >)->execute(< values >) (with extra error handling ofcourse).

所以我认为或者MySQL的事务处理系统不起作用,或者PDO的灵巧性不起作用,或者我发现有问题.

So i think or the transaction system of MySQL doesn't work, or PDO's implenmentaties doesn't work or i see something wrong.

有人知道是什么问题吗?

Does anybody know what the problem is?

推荐答案

检查您的数据库类型是否等于innoDB.一句话,您必须检查您的数据库是否支持事务.

Check if your type of database equals innoDB. In one word you must check if your database supports transactions.

这篇关于交易回滚不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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