Prueba así:
Código PHP:
Ver original<?php
try {
$db = new PDO('mysql:host=localhost;dbname=ejercicio', 'root', '');
} catch (PDOException $e) {
echo $e->getMessage();
}
A ver si te está funcionando o no, si sale algún mensaje colocalo aquí.
Saludos.