<?php
$dbname = 'asdf';
$dbuser = 'asdf';
$dbpass = 'asdf';
$dbhost = 'anywhere';
$connection = mysqli_init();
$connection->options(MYSQLI_OPT_CONNECT_TIMEOUT, 10);
$connection->real_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
mysqli_select_db($connection, $dbname) or die("Could not open the db '$dbname'");
$test_query = "SHOW TABLES FROM $dbname";
$result = mysqli_query($connection, $test_query);
$tblCnt = 0;
while($tbl = mysqli_fetch_array($result)) {
$tblCnt++;
#echo $tbl[0]."<br />\n";
}
if (!$tblCnt) {
exec("systemctl restart mysql");
echo "Wasn't connected, restarted mysql.";
} else {
echo "Connected: $tblCnt tables";
} 
?>