jodunno Posted July 11, 2020 Share Posted July 11, 2020 Hello everyone, quick description of 'error handling' so that everyone understands the solution i am seeking. let php and the database handle the error is not an appropriate answer here. find out what i mean: using xampp, go to a login screen of your website, then turn off the database before submitting the login data. the connection will be attempted then fail. the browser will display its own error page which is white bg with a message. this is ridiculous. i made a custom handler that allows me to ignore this failure and show my own website with an error message. now how can i detect an error with a select or update statement? i am not a db designer, so i really don't know how to do it. what say i fetch filed['testmyerror'] and it doesn't exist or there is a problem. how do i write php code that is used to ignore this problem and display my own message. naturally i will log the error and/or log and send email to myself. anyone able to help? just a tip in the right direction? Thank you very much, i appreciate this forum and its members always. Quote Link to comment https://forums.phpfreaks.com/topic/311070-database-error-handling-using-php/ Share on other sites More sharing options...
benanamen Posted July 11, 2020 Share Posted July 11, 2020 You can use set_exception_handler to create a custom exemption function. https://www.php.net/manual/en/function.set-exception-handler.php Quote Link to comment https://forums.phpfreaks.com/topic/311070-database-error-handling-using-php/#findComment-1579526 Share on other sites More sharing options...
jodunno Posted July 11, 2020 Author Share Posted July 11, 2020 Hello benanamen, Thank you very much. I didn't know that i could do custom handling. I should probably read the php manual a little closer. My apologies for this lack of knowledge. Best wishes. Quote Link to comment https://forums.phpfreaks.com/topic/311070-database-error-handling-using-php/#findComment-1579527 Share on other sites More sharing options...
benanamen Posted July 11, 2020 Share Posted July 11, 2020 3 hours ago, benanamen said: custom exemption function Ooops, meant exception. Quote Link to comment https://forums.phpfreaks.com/topic/311070-database-error-handling-using-php/#findComment-1579532 Share on other sites More sharing options...
kicken Posted July 12, 2020 Share Posted July 12, 2020 Alternatively, configure your web server to show a particular page on error. For apache you might do for example ErrorDocument 500 /500.html Exact configuration will depend on your server version and setup. 1 Quote Link to comment https://forums.phpfreaks.com/topic/311070-database-error-handling-using-php/#findComment-1579554 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.