montgomery Posted February 17, 2008 Share Posted February 17, 2008 Once in a while when our hosting company has problems out site breaks and shows some ugly error messages: "Warning: mysql_connect(): Too many connections in ./settings.inc.php on line 90" This of course looks very unprofessional. What can I do to redirect the user to an "under maintenance" page, every time the problem occurs? Thanks a lot!! Montgomery Quote Link to comment https://forums.phpfreaks.com/topic/91571-warning-mysql_connect-is-if-possible-to-redirect-if-error-message/ Share on other sites More sharing options...
wildteen88 Posted February 17, 2008 Share Posted February 17, 2008 What you could do is do the following when mysql_connect returns an error @mysql_connect('lcoalhost', 'username', 'passsword') or die('maintenance message here'); Quote Link to comment https://forums.phpfreaks.com/topic/91571-warning-mysql_connect-is-if-possible-to-redirect-if-error-message/#findComment-469027 Share on other sites More sharing options...
pocobueno1388 Posted February 17, 2008 Share Posted February 17, 2008 You could do something like this: <?php if ($conn = mysql_connect("....")){ //connection made } else { //need to redirect header("Location: www.sample.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/91571-warning-mysql_connect-is-if-possible-to-redirect-if-error-message/#findComment-469028 Share on other sites More sharing options...
montgomery Posted February 17, 2008 Author Share Posted February 17, 2008 I found the line 90 in settings.inc.php where the error occurs: if(!mysql_connect($DbHost,$DbUser,$DbPassword)) { $NOTCONNECTED = TRUE; } could I just change it to: if(!mysql_connect($DbHost,$DbUser,$DbPassword)) { $NOTCONNECTED = TRUE; header("Location: www.sample.php"); } Quote Link to comment https://forums.phpfreaks.com/topic/91571-warning-mysql_connect-is-if-possible-to-redirect-if-error-message/#findComment-469054 Share on other sites More sharing options...
pocobueno1388 Posted February 17, 2008 Share Posted February 17, 2008 Quote could I just change it to: if(!mysql_connect($DbHost,$DbUser,$DbPassword)) { $NOTCONNECTED = TRUE; header("Location: www.sample.php"); } Yes, although the variable $NOTCONNECTED will be linked somewhere else in the script, so I would check that out to see what it does. Quote Link to comment https://forums.phpfreaks.com/topic/91571-warning-mysql_connect-is-if-possible-to-redirect-if-error-message/#findComment-469057 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.