Pheasant\Database\Mysqli\Transaction::execute PHP Method

execute() public method

public execute ( )
    public function execute()
    {
        $this->results = array();
        try {
            $this->_connection->execute('BEGIN');
            $this->_events->trigger('startTransaction', $this->_connection);
            $this->_connection->execute('COMMIT');
            $this->_events->trigger('commitTransaction', $this->_connection);
        } catch (\Exception $e) {
            $this->_connection->execute('ROLLBACK');
            $this->_events->trigger('rollbackTransaction', $this->_connection);
            throw $e;
        }
        return $this->results;
    }

Usage Example

Example #1
0
 public function testDeferEventsFireOnRollback()
 {
     $connection = \Mockery::mock('\\Pheasant\\Database\\Mysqli\\Connection');
     $connection->shouldReceive('execute')->with('BEGIN')->once();
     $connection->shouldReceive('execute')->with('ROLLBACK')->once();
     $events = \Mockery::mock();
     $events->shouldReceive('cork')->once()->andReturn($events);
     $events->shouldReceive('discard')->once()->andReturn($events);
     $events->shouldReceive('uncork')->once()->andReturn($events);
     $transaction = new Transaction($connection);
     $transaction->deferEvents($events);
     $transaction->callback(function () {
         throw new \Exception("Llamas :( :)");
     });
     $this->setExpectedException('\\Exception');
     $transaction->execute();
 }