Illuminate\Database\Connection::beginTransaction PHP Метод

beginTransaction() публичный Метод

Start a new database transaction.
public beginTransaction ( ) : void
Результат void
    public function beginTransaction()
    {
        if ($this->transactions == 0) {
            try {
                $this->getPdo()->beginTransaction();
            } catch (Exception $e) {
                if ($this->causedByLostConnection($e)) {
                    $this->reconnect();
                    $this->pdo->beginTransaction();
                } else {
                    throw $e;
                }
            }
        } elseif ($this->transactions >= 1 && $this->queryGrammar->supportsSavepoints()) {
            $this->getPdo()->exec($this->queryGrammar->compileSavepoint('trans' . ($this->transactions + 1)));
        }
        ++$this->transactions;
        $this->fireConnectionEvent('beganTransaction');
    }

Usage Example

Пример #1
0
 /**
  * Save multiple notifications sent
  * at once.
  *
  * @param  array $notifications
  * @return mixed
  */
 public function storeMultiple(array $notifications)
 {
     $this->db->beginTransaction();
     $stackId = $this->db->table($this->notification->getTable())->max('stack_id') + 1;
     foreach ($notifications as $key => $notification) {
         $notifications[$key]['stack_id'] = $stackId;
     }
     $insert = $this->db->table($this->notification->getTable())->insert($notifications);
     $this->db->commit();
     return $insert;
 }
All Usage Examples Of Illuminate\Database\Connection::beginTransaction