How to check if a transaction was started in Zend

Asked

Viewed 193 times

2

I have a method where a BEGIN TRANSACTION in Zend 1.12. As it is used in many places, it has occurred that a method that calls it already starts a BEGIN TRANSACTION, thus generating a Exception.

I want to check before starting if a transaction has already been created. How can I do this in Zend?

1 answer

1

The method beginTransaction() in class Zend_Db_Adapter_Abstract is as follows:

public function beginTransaction()
{
    $this->_connect();
    $q = $this->_profiler->queryStart('begin', Zend_Db_Profiler::TRANSACTION);
    $this->_beginTransaction();
    $this->_profiler->queryEnd($q);
    return $this;
}

In this method he calls the method _beginTransaction(), which is abstract and should be implemented by the Zend Adapters. Therefore, from what I noticed in Zend’s code, there is no way to verify whether the transaction has already started or not. You should do this control in the application that uses Zend.

What you can do is enable the profiler (not recommended) and search through the method getProfiler(). From it, get the profiles of each query by the method getQueryProfiles() and check if any of them represent the start of a transaction.

However, as I said above, it is not recommended to leave the profiler enabled 100% of the time because it decreases the performance of the program. You can use it to debug your application and implement manual transaction control. :)

  • Very enlightening, I will wait a while to see if there are other possibilities, thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.