jeudi 22 décembre 2016

What would happen if DB::beginTransaction is called without DB::commit() in laravel5?

Normall, when using DB::beginTransaction(), it is used with DB::rollBack()

Something like this:

DB::beginTrnsaction();
try {
    DB::insert(...);
    DB::insert(...);
    DB::insert(...);

    DB::commit();
    // all good
} catch (\Exception $e) {
    DB::rollback();
    // something went wrong
}

However, what if I forget to add the try catch loop?

i.e.

DB::beginTrnsaction();
DB::insert(...);
DB::insert(...);
DB::insert(...);
DB::commit();

Will the database be changed if one of the insert goes wrong? Or it will automatically rollback?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire