vendredi 13 avril 2018

Laravel Eloquent (PDO): Check that Transaction is Active

I feel that this should be a simple answer. However, I haven't been able to find a direct answer in the documents or anywhere else.

In the Laravel PHP framework, I have a situation similar to the following where I open a database-transaction:

(Of course, my example is grossly simplified from the real-world stuff I'm working with, so please refrain from "why are you doing it this way" type responses). It's the principle that interests me.

try {

    if ($conditions == $criteria) {
       DB::connection('oracle')->beginTransaction();
    }
    // blah...

Later on in the code, I simply want to check whether a transaction is on-going. The pseudo-code for my condition statement would look something like this:

    if ( DB::connection('oracle')->transactionIsOngoing() ) {

        // do some stuff with the on-going transaction
        DB::connection('oracle')->commit();

        // if I were to execute "DB::connection('oracle')->transactionIsOngoing()"
        // again here it would return FALSE, because the commit command has
        // completed the open transaction

    }

What is the actual code that I should use to replace DB::connection('oracle')->transactionIsOngoing() with?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire