<?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()}";
}