Skip to content

Instantly share code, notes, and snippets.

@rlandas
Created November 21, 2012 22:22
Show Gist options
  • Save rlandas/4128250 to your computer and use it in GitHub Desktop.
Save rlandas/4128250 to your computer and use it in GitHub Desktop.
ZF2: How to using DB transaction with zf2
public function add($data) {
try {
/**
* @var \Zend\Db\Adapter\Driver\Pdo\Connection
*/
$connection = $this->itemTable->adapter->getDriver()->getConnection();
$connection->beginTransaction();
$connection->commit();
} catch (Exception $e) {
$connection->rollback();
}
return $this->itemTable->add($data);
}
// @see http://giaule.com/2012/10/27/how-to-using-transaction-with-zf2/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment