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?
Illuminate\Database\ConnectionInterface::transaction
has a transactionLevel
property which returns the number of active transactions.
Documentation can be found here: https://laravel.com/api/5.6/Illuminate/Database/ConnectionInterface.html#method_transactionLevel
To get the transaction level you can use
Illuminate\Support\Facades\DB::transactionLevel();
it returns integer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With