public function __construct($options)
{
if (is_object($options)) {
$options = (array) $options;
}
if (!isset($options['options'])) {
$options['options'] = [];
}
$this->_options = $options['options'];
$this->_options[\PDO::ATTR_ERRMODE] = \PDO::ERRMODE_EXCEPTION;
$this->_username = isset($options['username']) ? $options['username'] : null;
$this->_password = isset($options['password']) ? $options['password'] : null;
unset($options['username'], $options['password'], $options['options']);
if (isset($options['dsn'])) {
$this->_dsn = $options['dsn'];
} else {
$dsn_parts = [];
foreach ($options as $k => $v) {
$dsn_parts[] = $k . '=' . $v;
}
$this->_dsn = implode(';', $dsn_parts);
}
$this->_pdo = new \PDO($this->_type . ':' . $this->_dsn, $this->_username, $this->_password, $this->_options);
}