Click to See Complete Forum and Search --> : [RESOLVED] What Does "@" Do In @mysql_query()?


chestertb
10-16-2006, 09:32 PM
I was reading through some code a contract programmer wrote for me and I came across this...

$result = @mysql_query($query);

What does the "@" do?

Thanks
CTB

NogDog
10-16-2006, 10:02 PM
It suppresses the automatic error reporting that will be done by that function if it should generate a run-time error. You should only do this if your code checks the return value and does some sort of error-handling if it fails; otherwise you may end up spending an unnecessary amount of time tracking down a bug there. For instance:

$result = @mysql_query($query);
if(!$result)
{
die("Database error near line " . __LINE__ . ". Please contact the webmaster.");
}

pcthug
10-17-2006, 02:15 AM
Error Control Operators (http://www.php.net/operators.errorcontrol)

chestertb
10-18-2006, 02:36 AM
Thanks guys.
Dog... I spent an awful amount of time tracking down bugs in the code I write anyway so I probably wouldn't notice anything different. ;-)