Skip to content

Instantly share code, notes, and snippets.

@Asselberghs
Created August 4, 2015 10:16
Show Gist options
  • Save Asselberghs/4897d24a908f7ff2d92d to your computer and use it in GitHub Desktop.
Save Asselberghs/4897d24a908f7ff2d92d to your computer and use it in GitHub Desktop.
Connecting to a MySQL Database Using PDO.
<?php
$dsn = 'mysql:dbname=Database_Name;host=IP_Address';
$user = 'Username';
$pass = 'Password';
try {
$db = new PDO($dsn, $user, $pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e) {
die('Could not connect to database:<br />' . $e->getMessage());
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment