Laravel: Verwenden Sie Try ... Fang mit db :: transaktion ()Php

PHP-Programmierer chatten hier
Anonymous
 Laravel: Verwenden Sie Try ... Fang mit db :: transaktion ()

Post by Anonymous »

Wir alle verwenden db :: transaction () für mehrere Einfügenabfragen. Sollte es versuchen, sich zu versuchen ... fangen darin platziert werden oder einwickeln? Ist es überhaupt notwendig, einen Versuch hinzuzufügen ... fangen < /code> Wenn eine Transaktion automatisch fehlschlägt, wenn etwas schief geht?

Code: Select all

// try...catch
try {
// Transaction
$exception = DB::transaction(function() {

// Do your SQL here

});

if(is_null($exception)) {
return true;
} else {
throw new Exception;
}

}
catch(Exception $e) {
return false;
}
< /code>

Gegenteil, a db :: transaction () < /code> Wickeln Sie einen Versuch ein ... catch: < /p>

// Transaction
$exception = DB::transaction(function() {
// try...catch
try {

// Do your SQL here

}
catch(Exception $e) {
return $e;
}

});

return is_null($exception) ? true : false;
< /code>

oder einfach eine Transaktion mit einem Versuch ... fangen < /p>

// Transaction only
$exception = DB::transaction(function() {

// Do your SQL here

});

return is_null($exception) ? true : false;

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post