How to check if a transaction was started in Zend

2

I have a method where a BEGIN TRANSACTION is started 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 Exception .

I want to check before starting if a transaction already exists. How can I do this on Zend?

    
asked by anonymous 26.02.2014 / 21:51

1 answer

1

The beginTransaction() method 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 it calls the _beginTransaction() method, which is abstract and must be implemented by Zend adapters. So from what I noticed in the Zend code, there is no way to check 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 fetch it using the getProfiler() method. From there, get the profiles of each query by the getQueryProfiles() method and check if any of them represent the beginning of a transaction.

However, as I said above, it is not recommended to leave 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. :)

    
26.02.2014 / 22:09