Skip to content

Instantly share code, notes, and snippets.

@ismnoiet
Last active March 6, 2016 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ismnoiet/33bf2df5bcbefe709654 to your computer and use it in GitHub Desktop.
Save ismnoiet/33bf2df5bcbefe709654 to your computer and use it in GitHub Desktop.
<?php
// Create a pdo instance
$host = 'localhost';
$database_name = 'databasename';
$username='username by default it is root';
$password='the password associated with the current user';
try{
// check if there is exception
$pdo = new PDO("mysql:host=$host;dbname=$database_name","$username","$password");
// now we've connected successfully to $database_name database
// and we can do whatever we want with it.
}
catch(PDOException $e){
// show a message explaining what is goining wrong.
echo $e->getMessage();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment