Skip to content

Instantly share code, notes, and snippets.

@samsargent samsargent/gist:5429552
Last active Dec 16, 2015

Embed
What would you like to do?
PHP: SlimPHP PDO database connection
<?php
function getConnection() {
$dbhost="127.0.0.1";
switch(ENV){
case 'dev':
$dbuser="username";
$dbpass="password";
$dbname="databasename";
break;
case 'prod':
$dbuser="username";
$dbpass="password";
$dbname="databasename";
break;
}
$dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $dbh;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.