Altec Posted October 21, 2008 Share Posted October 21, 2008 I really don't know how to explain my problem without posting code first, so bear with me. // Connect to the database if(!mysql_connect('localhost', DB_USER, DB_PASS)) { $page = new Page('error.html'); $page->replace_tags(array( 'TYPE_OF_ERROR' => $string['DATABASE_CONNECT_ERROR'], 'ERROR_CONTENT' => mysql_error(), )); $page->output(); exit; } All that does is attempt to connect to the MySQL database. If it fails it outputs an error page (error.html). However, it automatically outputs an error THEN outputs the error page, which results in this: <br /> <b>Warning</b>: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Access denied for user 'DB_USER'@'localhost' (using password: YES) in <b>post.php</b> on line <b>10</b><br /> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> How can I prevent (or "catch") the error from being displayed? Link to comment https://forums.phpfreaks.com/topic/129347-mysql-error-handling/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 21, 2008 Share Posted October 21, 2008 On a live server, the display_errors setting should be OFF. On a development server the display_errors setting should be ON and the additional information that is in the messages should be used to help you in fixing the problem in your code. Code does not normally generate any errors, only for unexpected conditions. Link to comment https://forums.phpfreaks.com/topic/129347-mysql-error-handling/#findComment-670578 Share on other sites More sharing options...
Altec Posted October 21, 2008 Author Share Posted October 21, 2008 I assume in the php.ini? Apparently my host has left that on. Is it a major security concern? Link to comment https://forums.phpfreaks.com/topic/129347-mysql-error-handling/#findComment-670580 Share on other sites More sharing options...
Altec Posted October 21, 2008 Author Share Posted October 21, 2008 Right now I'm doing: ini_set('display_errors', 0); But you're saying that on a live server is should be off by default? Link to comment https://forums.phpfreaks.com/topic/129347-mysql-error-handling/#findComment-670587 Share on other sites More sharing options...
PFMaBiSmAd Posted October 21, 2008 Share Posted October 21, 2008 If the master php.ini is not accessible, the setting can be turned off in a .htaccess file (when php is running as an Apache module) or in a local php.ini (when php is running as a CGI application.) Turning it off in each of your files is just extra work, you might forget to do it in some files, and if you need to turn it on, you would need to change each affected file, because the setting in a script overrides any global setting. Link to comment https://forums.phpfreaks.com/topic/129347-mysql-error-handling/#findComment-670599 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.