Skip to content

Instantly share code, notes, and snippets.

@makerneo-com
Created July 11, 2014 03:38
Show Gist options
  • Select an option

  • Save makerneo-com/9c738d500a36ad80c121 to your computer and use it in GitHub Desktop.

Select an option

Save makerneo-com/9c738d500a36ad80c121 to your computer and use it in GitHub Desktop.
<?php
$parseDsn = function($pdoDsn)
{
$dsnInfo = parse_url($pdoDsn);
if ( empty($dsnInfo['scheme'])) {
throw new \Exception("invalid dsn:$pdoDsn");
}
$pathInfo = explode(';', $dsnInfo['path']);
foreach ($pathInfo as $p) {
$itemInfo = explode('=', $p);
if (count($itemInfo) != 2) {
throw new \Exception("invalid dsn:$pdoDsn");
}
$dsnInfo[$itemInfo[0]] = $itemInfo[1];
}
return $dsnInfo;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment