1
    DB::beginTransaction();
    try{
          //my logic  
          if(bad logic) throw new \Exception();

          DB::commit();
          return true;
    }catch (\Exception $e) {
          DB::rollback();
          return false;
    }

So what will happen if bad logic throws new exception? DB::commit() will not be called, so recored will not be saved in database. So why the hell I need to write DB:rollback() at all?

O. Shekriladze
  • 1,346
  • 1
  • 19
  • 36
  • 3
    It will cancel the transaction and release any locks. Sure it should cancel it when the request dies, but you shouldn't rely on it. Here's an [SQL server question about it](https://stackoverflow.com/questions/7971903/do-i-need-to-call-rollback-if-i-never-commit), and a [generic question about it](https://stackoverflow.com/questions/309834/should-i-commit-or-rollback-a-read-transaction) – aynber Dec 19 '18 at 19:32

0 Answers0