Doctrine\DBAL\Connection::connect PHP Method

connect() public method

Establishes the connection with the database.
public connect ( ) : boolean
return boolean TRUE if the connection was successfully established, FALSE if the connection is already open.
    public function connect()
    {
        if ($this->_isConnected) {
            return false;
        }
        $driverOptions = isset($this->_params['driverOptions']) ? $this->_params['driverOptions'] : array();
        $user = isset($this->_params['user']) ? $this->_params['user'] : null;
        $password = isset($this->_params['password']) ? $this->_params['password'] : null;
        $this->_conn = $this->_driver->connect($this->_params, $user, $password, $driverOptions);
        $this->_isConnected = true;
        if (false === $this->autoCommit) {
            $this->beginTransaction();
        }
        if ($this->_eventManager->hasListeners(Events::postConnect)) {
            $eventArgs = new Event\ConnectionEventArgs($this);
            $this->_eventManager->dispatchEvent(Events::postConnect, $eventArgs);
        }
        return true;
    }

Usage Example

 /**
  * @return Connection
  */
 public function getConnection()
 {
     if (false === $this->connection->ping()) {
         $this->connection->close();
         $this->connection->connect();
     }
     return $this->connection;
 }
All Usage Examples Of Doctrine\DBAL\Connection::connect