Handling database errors
Posted: Fri Mar 02, 2012 2:17 am
I've created a database connection class that is extended by a search class. The database class throws an exception when any database connection and selection errors occur.
The working of the search class is dependant on the availability of the database so i thought about modifying the database connection class not to display an error message when it fails but to create an error array, containing any errors returned from database connection / select issues. Based on the presence of this array the search class will then display (or not display) the search from. Should the form be absent there will be an error message displayed to notify users that the search option is unavailable. To notify me about the error i have an error reporting option (via email) in place.
My thinking behind this is that i don't want visitors to know specifics (such as an unavailable database) about why the search option isn't working; they should only know that it isn't available. By not displaying the search form i am also limiting errors resulting from functions such as mysqli_real_escape_string() or mysqli_query(); I do use the error control operator but i would rather prevent the error from happening than letting it die quietly.
Is this approach valid or should i rethink it?
The working of the search class is dependant on the availability of the database so i thought about modifying the database connection class not to display an error message when it fails but to create an error array, containing any errors returned from database connection / select issues. Based on the presence of this array the search class will then display (or not display) the search from. Should the form be absent there will be an error message displayed to notify users that the search option is unavailable. To notify me about the error i have an error reporting option (via email) in place.
My thinking behind this is that i don't want visitors to know specifics (such as an unavailable database) about why the search option isn't working; they should only know that it isn't available. By not displaying the search form i am also limiting errors resulting from functions such as mysqli_real_escape_string() or mysqli_query(); I do use the error control operator but i would rather prevent the error from happening than letting it die quietly.
Is this approach valid or should i rethink it?