Try to increase error mode:
setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
echo 'Connected to Database
';
$sql = "SELECT * FROM stickercollections";
foreach ($dbh->query($sql) as $row)
{
echo $row["collection_brand"] ." - ". $row["collection_year"] ."
";
}
$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
EDIT:
pdo.error-handling says, you can alternatively use pdo.errorcode and pdostatement.errorcode (or like) to get more info, but I think throw exception is better way to handle bad connections, not resolved hosts etc.