JasonDaly.name

PHP, Ruby, Symfony, Rails, Doctrine, MooTools. Web Development.
March 3, 2010

Symfony 1.4 + Doctrine 1.2 - Transactions

Hoping there is a simpler way that I am missing, here is how to begin a new transaction with Doctrine 1.2 through Symfony 1.4. It was the call to sfDoctrineDatabase::getDoctrineConnection() which I had to lookup in the docs1.

$connection = sfContext::getInstance()->getDatabaseManager()->getDatabase('default')->getDoctrineConnection();  
$connection->beginTransaction();    
try {
  // Do work for the transaction ...
  $connection->commit();
} catch (Exception $e) {
  $connection->rollback();
  // Handle exception ...
}                  

1 note Tags: symfony symfony 1.4 doctrine doctrine 1.2 transaction doctrine_connection

  1. d4ly posted this