smerny Posted July 19, 2010 Share Posted July 19, 2010 i have ajax refreshing some content... and if my website goes down while someone is on it, they see this: Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) how do i prevent this? Quote Link to comment https://forums.phpfreaks.com/topic/208227-prevent-cant-connect-error-message/ Share on other sites More sharing options...
radar Posted July 19, 2010 Share Posted July 19, 2010 remove the refresh? Quote Link to comment https://forums.phpfreaks.com/topic/208227-prevent-cant-connect-error-message/#findComment-1088365 Share on other sites More sharing options...
smerny Posted July 19, 2010 Author Share Posted July 19, 2010 defeat the purpose? Quote Link to comment https://forums.phpfreaks.com/topic/208227-prevent-cant-connect-error-message/#findComment-1088369 Share on other sites More sharing options...
radar Posted July 20, 2010 Share Posted July 20, 2010 have you tried putting an @ at the beginning of your mysql commands? thats really the only way i know to stop those but even that doesnt work all the time. Quote Link to comment https://forums.phpfreaks.com/topic/208227-prevent-cant-connect-error-message/#findComment-1088760 Share on other sites More sharing options...
Philip Posted July 20, 2010 Share Posted July 20, 2010 ... proper error checking? Quote Link to comment https://forums.phpfreaks.com/topic/208227-prevent-cant-connect-error-message/#findComment-1088776 Share on other sites More sharing options...
smerny Posted July 21, 2010 Author Share Posted July 21, 2010 ... proper error checking? this is what i'm looking/asking for in this thread Quote Link to comment https://forums.phpfreaks.com/topic/208227-prevent-cant-connect-error-message/#findComment-1089179 Share on other sites More sharing options...
Zane Posted July 21, 2010 Share Posted July 21, 2010 mysql_connect(blah blah blah) or die("Error Message") Most people will argue that trigger_error() is the "proper way" to do it, but really, the proper way is to have a Database Class and have it do all that error checking stuff for you. if you use the mysql_error() function .. (instead of "Error Message") it will give you the reason the connection failed, but for some reason I don't think you want that. Quote Link to comment https://forums.phpfreaks.com/topic/208227-prevent-cant-connect-error-message/#findComment-1089181 Share on other sites More sharing options...
PFMaBiSmAd Posted July 21, 2010 Share Posted July 21, 2010 Actually, because putting or anything() on the end of a statement doesn't address the execution path the remainder of your code takes when there is an error, it is only useful for troubleshooting problems and not ideal for application error handling. On an error, your code should - A) Output a user error message, something like "Due to a server error, this page cannot be accessed at this time." B) Log all the available information about the error - who (ip address, logged in visitor id) caused the error (in case a hacker managed to cause the error or a legitimate visitor happened to do something that your logic could not handle), what the actual data values or query was that caused the error and what error resulted, when the error occurred (so that you could both see if someone is triggering a series of errors to bring your database server down or to match outages with actual problems with your database server), where in your code (file and line number) the error occurred. C) Finish processing and output the remainder of your page that is not dependent on the error that did occur. You should also have display_errors set to OFF and log_errors set to ON for a live server (error_reporting should always be E_ALL or higher) so that all php detected errors are not displayed but they are logged. Quote Link to comment https://forums.phpfreaks.com/topic/208227-prevent-cant-connect-error-message/#findComment-1089191 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.