private function parseDsn($dsn)
{
if (empty($dsn) || false === ($pos = strpos($dsn, ":"))) {
throw new Exception("Empty DSN string");
}
$this->dsn = $dsn;
$this->dbType = strtolower(substr($dsn, 0, $pos));
if (empty($this->dbType)) {
throw new Exception("Missing database type from DSN string");
}
$dsn = substr($dsn, $pos + 1);
foreach (explode(";", $dsn) as $kvp) {
$kvpArr = explode("=", $kvp);
$this->dsnArray[strtolower($kvpArr[0])] = $kvpArr[1];
}
if (empty($this->dsnArray['host']) && empty($this->dsnArray['unix_socket'])) {
throw new Exception("Missing host from DSN string");
}
$this->host = !empty($this->dsnArray['host']) ? $this->dsnArray['host'] : $this->dsnArray['unix_socket'];
if (empty($this->dsnArray['dbname'])) {
throw new Exception("Missing database name from DSN string");
}
$this->dbName = $this->dsnArray['dbname'];
return true;
}