Home > Uncategorized > Magento DB transaction commit rollback sniplet

Magento DB transaction commit rollback sniplet

Took me a while to find out how to do this… as there was no good examples on the web.
So, here it is… so I can find it again.

keywords:
db database transaction rollback commit magento zend.

try {
    $write = Mage::getSingleton('core/resource')->getConnection('core_write');
    $write->beginTransaction();

// do stuff here

    $write->commit();
} catch (Exception $e) {
    mage::log(__METHOD__ . ':' . __LINE__ . ': Rollback happened.');
    $write->rollback();
}

Please drop a line if you found this useful. Thanks!

Categories: Uncategorized Tags:
  1. MP
    October 30th, 2011 at 15:28 | #1

    Thanks

  1. No trackbacks yet.