Possible Duplicates:
Reference – What does this symbol mean in PHP?
What does @ mean in PHP?
I have a line in my code which looks like this:
@mysql_select_db($dbname) or die( “Error: Unable to select database”);
It works, but I want to know what the @ does and why it is there.
In this case, the
@will suppress the regular PHP database connection error (which may contain sensitive information). In case of a connection error, the “or die” part will be executed, failing with a generic error message. The line is probably copied from a “quick and dirty” example.Using the error suppression operator
@is considered bad style, especially when other forms of error handling are missing. It complicates debugging – how can you find out about in error without any indication that it occured? In a production system it’s better to log all errors to a file and suppress the rendering of errors on the page. You could do that in thephp.inifile or (if you are on a shared host and not allowed to make config changes) with the following code.