Preview:
<?php
//Database credentials
$host = 'localhost';
$port = 3306;
$dbName = 'blog';
$username = 'root';
$password = '';

$dsn = "mysql:host={$host};dbname={$dbName};port={$port};charset=utf8";

try {
    // create PDO instance
    $pdo = new PDO($dsn, $username, $password);

//    set PDO to throw exceptions on error
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//    Fetch as associative array
    $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);

} catch (PDOException $e) {
// if error catch
    echo "Connection Failed {$e->getMessage()}";
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter