Forum Moderators: coopster
$dbh = @mysqli_connect('localhost', user_' . $_SERVER['db_user'], $_SERVER['db_pass'], 'database');
if (mysqli_connect_errno()) {
// "mysql_restart.dat" is an empty text file, I just use it to
// limit restarts to once per minute
if (time() - filemtime('/home/account/mysql_restart.dat') > 60) {
mail('me@gmail.com',
'MySQL Restarted',
mysqli_connect_error());
exec('/etc/rc.d/init.d/mysql restart');
touch('/home/account/mysql_restart.dat');
}
include '/nodb.php';
exit;
} if ($_SERVER['db_user'] && $_SERVER['db_pass'])
$dbh = @mysqli_connect('localhost', user_' . $_SERVER['db_user'], $_SERVER['db_pass'], 'database');
else {
if (time() - filemtime('/home/account/mysql_restart.dat') > 60) {
mail('me@gmail.com',
'Apache Failed',
'Apache failed, page refreshed');
touch('/home/account/mysql_restart.dat');
}
// refresh the page after 2 seconds
header("Refresh:2");
} What about storing the MySQL credentials in the php.ini file? and access the values using get_cfg_var
Also, you should find out why MySQL can be unreachable and needing to be restarted. This is not normal. There is no reason MySQL stops working. If it's a matter of too many connections, then MySQL should not be restarted.