⇧
vadnica-logo
My Services About the Project Telegram O meni O meni

Canceling Changes with the rollBack() Method

The rollBack() method cancels the currently active transaction and reverts the database back to the exact state it was in before beginTransaction() was called. This is crucial for operations where multiple commands must succeed together (e.g., a money transfer: deducting from one account and adding to another). If any of those steps fail, rollBack() ensures that the database does not end up in an inconsistent or partially updated state.

EXAMPLE
RESULT
The result will be displayed here...

Practical Application: This method is almost always used inside a catch block. When PHP detects an error (an exception), it automatically triggers a rollback of all commands already sent to the database during that specific transaction. Check the process at home by following these steps: