implements Phalcon\Mvc\Model\TransactionInterface
Transactions are protective blocks where SQL statements are only permanent if they can all succeed as one atomic action. Phalcon\Transaction is intended to be used with Phalcon_Model_Base. Phalcon Transactions should be created using Phalcon\Transaction\Manager.
try { $manager = new \Phalcon\Mvc\Model\Transaction\Manager(); $transaction = $manager->get(); $robot = new Robots(); $robot->setTransaction($transaction); $robot->name = 'WALL·E'; $robot->created_at = date('Y-m-d'); if ($robot->save() == false) { $transaction->rollback("Can't save robot"); } $robotPart = new RobotParts(); $robotPart->setTransaction($transaction); $robotPart->type = 'head'; if ($robotPart->save() == false) { $transaction->rollback("Can't save robot part"); } $transaction->commit(); } catch(Phalcon\Mvc\Model\Transaction\Failed $e) { echo 'Failed, reason: ', $e->getMessage(); }
Phalcon\Mvc\Model\Transaction constructor
Sets transaction manager related to the transaction
Starts the transaction
Commits the transaction
Rollbacks the transaction
Returns the connection related to transaction
Sets if is a reused transaction or new once
Sets flag to rollback on abort the HTTP connection
Checks whether transaction is managed by a transaction manager
Returns validations messages from last save try
Checks whether internal connection is under an active transaction
Sets object which generates rollback action
© 2011–2016 Phalcon Framework Team
Licensed under the Creative Commons Attribution License 3.0.
https://docs.phalconphp.com/en/latest/api/Phalcon_Mvc_Model_Transaction.html