Skip to content

Instantly share code, notes, and snippets.

@jshcrowthe
Created January 31, 2014 21:08
Show Gist options
  • Save jshcrowthe/8743178 to your computer and use it in GitHub Desktop.
Save jshcrowthe/8743178 to your computer and use it in GitHub Desktop.
PHP PDO Database Connect
function dbConnect($sql_hostName, $sql_Username, $sql_Password, $dbName = '') {
$server = $sql_hostName;
$name = $dbName;
$username = $sql_Username;
$password = $sql_Password;
$dsn = 'mysql:host='.$server.';dbname='.$name;
try {
$db = new PDO($dsn, $username, $password);
return $db;
} catch (PDOException $e) {
$error_message = $e->getMessage();
include('database_error.php');
exit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment