The ZF1 Zend_Db reference manual has an entire section on performing transactions.
The ZF2 Zend\Db reference manual lacks any documentation on transactions.
How do I perform transactions in ZF2? Example code would be helpful.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The missing documentation is curious.
To find out what happened, I had to dive into the API docs for Zend\Db\Adapter.
It looks like
beginTransaction,rollbackandcommitare defined in Zend\Db\Adapter\Driver\ConnectionInterface. This means that they are methods callable on every single adapter connection. Unfortunately the connection itself is rather buried.What I’m not clear on — and can’t provide an example for at this time — is figuring out which object you actually call these methods on. In the worst case, it looks like you might want to call
$adapter->getDriver()->getConnection()->beginTransaction().Eww.
I’m hoping someone else with more knowledge, and a copy of ZF2 handy, will see this and provide a better option.
Don’t forget that you can just issue
BEGIN TRANSACTION/ROLLBACK/COMMIT/SET autocommit=...SQL statements yourself. This is probably OK, as it doesn’t look like Zend\Db keeps track of the transaction state.