I am using PHP classes to connect to a data base. I am unable to solve a problem -- please help me out regarding this.
I have a function:
function getCampus($cm_id) //returns campus name
{
$this->query = "select cm_name from campus where cm_id = ".$cm_id.";";
$rd = $this->executeQuery();
@$data = $rd->fetch_assoc();
}
and when I remove @
from @$data
, it doesn't work. Please help me out: explain what i开发者_StackOverflow社区t is what an alternative way would be. Thanks.
@
is the error suppressor operator. Using it to prefix a line of code will suppress all non fatal errors. It is a bad idea to use it nearly every time.
If you get no output with it removed, try adding error_reporting(E_ALL)
in the top of your file or in a bootstrap type file and ensure display_errors = On
in php.ini
(you can also use ini_set('display_errors', 'on')
).
@ is used to suppress errors and warnings.
the @ is not your problem
The @
symbol in front of commands is used to ignore any errors that happen during the execution.
That line of code still fails when you put a @
in front of it, but you don't see it. Try to figure out what the problem with $rd->fetch_assoc()
is. Also, the query looks rather wrong.
The @
when used in a PHP expression suppresses errors for that expression. So, chances are "it's not working" because $rd->fetch_assoc()
is throwing an exception.
精彩评论