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());
}
}