This is just one of the many articles I’ve had on the back burner for months and I simply forgot about it. But a question today made me remember about it, so here it is. This is simply a test script for mysql, that will allow you to verify several things; Available open connections for Mysql or to verify if Mysql is simply down. All you have to do is create a test page with the following;
<?php
$link = mysql_connect(‘<server>’, ‘<username>’, ‘<password>’);
if (!$link) {
die(‘Could not connect: ‘ . mysql_error());
}
echo ‘Connected successfully’;
mysql_select_db(<database>);
?>
Make sure you replace the server, username, password and database variables with your own. Save it and make it web access via a URL. The script will either give you a blank screen if there is no available connections or if there are available connections it will state “Connected Sucessfully”. You can change that to whatever you wish to if the default “good” message is to bland, to say “All Go” or something more hip, I guess.
Its useful if you want to monitor your mysql remotely or if you have a monitoring service that checks for the text to show. If it sees the text missing, the monitor will error out and then we know there is a problem Houston.
That’s it.