Skip to content

Instantly share code, notes, and snippets.

@assertchris
Created December 10, 2015 02:26
Show Gist options
  • Save assertchris/851dfdf0ccc6807a0b8b to your computer and use it in GitHub Desktop.
Save assertchris/851dfdf0ccc6807a0b8b to your computer and use it in GitHub Desktop.
<?php
private function newConnectionString(array $config)
{
switch ($config->get("driver")) {
case "mysql": {
return sprintf(
"mysql:host=%s;port=%s;dbname=%s;unix_socket=%s;charset=%s",
$config->get("host"),
$config->get("port"),
$config->get("schema"),
$config->get("socket"),
$config->get("charset")
);
}
case "pgsql": {
return sprintf(
"pgsql:host=%s;port=%s;dbname=%s",
$config->get("host"),
$config->get("port"),
$config->get("schema")
);
}
case "sqlite": {
return sprintf(
"sqlite:%s",
$config->get("file")
);
}
case "sqlsrv": {
return sprintf(
"sqlsrv:Server=%s,%s;Database=%s",
$config->get("host"),
$config->get("port"),
$config->get("schema")
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment