Spot\Adapter\PDO\BaseAbstract::connection PHP Метод

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

Get database connection
public connection ( ) : object
Результат object PDO
    public function connection()
    {
        if (!$this->_connection) {
            if ($this->_dsn instanceof \PDO) {
                $this->_connection = $this->_dsn;
            } else {
                $dsnp = $this->parseDSN($this->_dsn);
                $this->_database = $dsnp['database'];
                // Establish connection
                try {
                    $dsn = $dsnp['adapter'] . ':host=' . $dsnp['host'] . ';dbname=' . $dsnp['database'];
                    if (isset($dsnp['port'])) {
                        $dsn .= ';port=' . $dsnp['port'];
                    }
                    $this->_connection = new \PDO($dsn, $dsnp['username'], $dsnp['password'], $this->_options);
                    // Throw exceptions by default
                    $this->_connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
                } catch (Exception $e) {
                    throw new \Spot\Exception($e->getMessage());
                }
            }
        }
        return $this->_connection;
    }