dongzhan2461 2012-09-10 18:32
浏览 110
已采纳

Zend Framework数据库事务 - 无法回滚

Alright, let me get this out of the way first. My question is similar to this: Cannot rollback transaction in Zend Framework

My tables are always innoDB, always. I've checked the table in question and it is indeed innoDB. On to the problem..

I have a database instance, and model instances running through this transaction hitting the same database:

$db->beginTransaction();

try { 
  // Run an insert
  $model_record->insert(array('single_item' => 'its value'));

  // More logic, and run an update.
  $model_record->this_value = 'that';

  // Save it
  $model_record->save();

  //Commit the transaction
  $db->commit();
} catch (Exception $e) {

  // It finds the rollback, yet does nothing.
  $db->rollBack();  
}

Now, the reason I found this to not be working is I exceeded the character limit on a row during a test to make sure all the logic in place was correct.

It did not rollback. On top of that the record with 'single_item', was in the database. But the updated values, were not.

Am I completely missing something small, I've never had transaction issues with MySQL & innoDB. Could this be MySQL related or ZF related? Any insight is helpful, thanks.

Update:

I've been conducting a few more tests and here are a few results that might help:

    $this->_db->beginTransaction();

    // This works
    $this->_db->insert('table_a', 
        array(
           'a_field' => 'transaction test',
        )
    );

    // This does not work, at all.  It inserts and does not rollback.  There is no commit.
    $_table_a_model->insert(
        array(
            'a_field' => 'transaction test',
        )
    );

    $this->_db->rollback();

Additional Update You need to get the instance of the model, and call a transaction on that.

$the_model = $this->_model->getAdapter();
$the_model->beginTransaction();

This leaves no room for transactions for multiple tables, without doing multiple transactions for each model instance. Any ideas out there without reverting to the base database instance?

  • 写回答

2条回答 默认 最新

  • dongxieyi9115 2012-09-10 21:42
    关注

    I figured it out. I have to use $db = Zend_Db_Table_Abstract::getDefaultAdapter(); and then run my transactions off that so all operations in multiple models work together under a single transaction. If anyone has a fix for that, feel free to comment.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP