Skip to content

Instantly share code, notes, and snippets.

@miss-invincible
Created June 11, 2016 20:50
Show Gist options
  • Save miss-invincible/f879a541d1ee9789a4c8f7ef0f3ab953 to your computer and use it in GitHub Desktop.
Save miss-invincible/f879a541d1ee9789a4c8f7ef0f3ab953 to your computer and use it in GitHub Desktop.
this code setsup PDO connection of php with mysql. for running it use command :
<?php
$servername='localhost';
$username='root';
$password='password';
try {
$conn = new PDO("mysql:host=$servername;dbname=testdb1", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment