Jump to content

mysql_connect() problem


robert_gsfame

Recommended Posts

mysql_connect("$host", "$username", "$password")or die("cannot connect to server");

 

i create a connection and let say there is a problem with the server so that the connection can't established

 

my question is how can i avoid the default error to be displayed which is

 

WARNING: mysql_connect() blablabla

 

as it is annoying to see such error message.

 

thx in advance

Link to comment
https://forums.phpfreaks.com/topic/233342-mysql_connect-problem/
Share on other sites

In a development environment you want those errors, so that you can spot them instantly and fix them. On a production environment however, you should have all error messages disabled anyway. If possible this should be set within the server's php.ini configuration file, but if not you can set it from within the code:

 

ini_set('display_errors', 0);

error_reporting() should still be enabled, albeit at a much higher level (fatal errors only), so that the server's error log still gets them. That way if users start reporting issues with the site, you can show them a "Sorry we're having technical difficulties" type error, but then look-up the actual error in the log. Best scenario would be also to get an email when ever a fatal error is triggered. Of course you don't want this on DEV, you just want all errors displayed instantly.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.