Pop\Db\Adapter\Pdo::__construct PHP Метод

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

Instantiate the PDO database connection object.
public __construct ( array $options ) : Pdo
$options array
Результат Pdo
    public function __construct(array $options)
    {
        if (!isset($options['type']) || !isset($options['database'])) {
            throw new Exception('Error: The proper database credentials were not passed.');
        }
        try {
            $this->database = $options['database'];
            $this->dbtype = strtolower($options['type']);
            if ($this->dbtype == 'sqlite') {
                $this->dsn = $this->dbtype . ':' . $options['database'];
                $this->connection = new \PDO($this->dsn);
            } else {
                if (!isset($options['host']) || !isset($options['username']) || !isset($options['password'])) {
                    throw new Exception('Error: The proper database credentials were not passed.');
                }
                if ($this->dbtype == 'sqlsrv') {
                    $this->dsn = $this->dbtype . ':Server=' . $options['host'] . ';Database=' . $options['database'];
                } else {
                    $this->dsn = $this->dbtype . ':host=' . $options['host'] . ';dbname=' . $options['database'];
                }
                $this->connection = new \PDO($this->dsn, $options['username'], $options['password']);
            }
        } catch (\PDOException $e) {
            throw new Exception('Error: Could not connect to database. ' . $e->getMessage());
        }
    }