The Drupal 7 DBTNG layer also supports transactions for database drivers that support transactions. If a driver does not support transactions, Drupal will automatically disable transaction functionality for you.
The key issue related to transactions in PHP is the potential for deadlocks due to multiple methods attempting to start transactions. If a transaction has been started in one method and a different method also attempts to start a transaction, the second transaction must wait until the first transaction completes until it can be started. Without proper protection, this can prevent the page load from completing. Thankfully, Drupal 7 protects against this behavior by providing the db_transaction
method, which will allow the second function to acknowledge and utilize the transaction started in the first method.
To utilize this functionality, you should call db_transaction
at the beginning of the method you want to have transaction support. As soon as the method exits...