Skip to content

Instantly share code, notes, and snippets.

@waaronking
Forked from jshcrowthe/phpPDOConnect.php
Last active August 29, 2015 14:01
Show Gist options
  • Save waaronking/82c81f4f0ca2e0b1cf16 to your computer and use it in GitHub Desktop.
Save waaronking/82c81f4f0ca2e0b1cf16 to your computer and use it in GitHub Desktop.
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