My web host is currently having an issue with one of the databases on my website, and I'm getting an error message when a connection is attempted. I happened to be on my site, so I learned about it nearly instantly, but now I'm wondering what the best way is to get some sort of notification for this type of issue in the future. My first instinct was to do an (abbreviated) code block like this:
try {
$DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
$DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
}
catch(PDOException $e) {
$msg = $e->getMessage();
mail($to,$subject,$msg,$headers);
}
But then I quickly saw the flaw was an email every single time my page was hit. I had a brief thought about entering the error in a database, but if there's a database connection issue, that doesn't seem like it would be particularly useful method of learning about the error.
Any other thoughts on how I can handle this scenario? Real time notification is preferred, but at notification beyond me accessing the website will work better than what I have now.