为什么删除错误抑制器后,一行代码无法工作?
我正在使用 PHP 类连接到数据库。我无法解决问题——请帮助我解决这个问题。
我有一个函数:
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();
}
当我从 @$data
中删除 @
时,它不起作用。请帮助我:解释一下替代方法是什么。谢谢。
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 it is what an alternative way would be. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
@
是错误抑制运算符。使用它作为一行代码的前缀将抑制所有非致命错误。几乎每次都使用它是一个坏主意。如果删除后没有任何输出,请尝试在文件顶部或引导类型文件中添加
error_reporting(E_ALL)
并确保中的
(您也可以使用display_errors = On
php.iniini_set('display_errors', 'on')
)。@
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 ensuredisplay_errors = On
inphp.ini
(you can also useini_set('display_errors', 'on')
).@ 用于抑制错误和警告。
@不是你的问题
@ is used to suppress errors and warnings.
the @ is not your problem
命令前面的
@
符号用于忽略执行过程中发生的任何错误。当您在该行代码前面放置
@
时,该行代码仍然会失败,但您看不到它。尝试找出$rd->fetch_assoc()
的问题是什么。此外,查询看起来相当错误。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.@
在 PHP 表达式中使用时会抑制该表达式的错误。因此,很可能“它不起作用”,因为$rd->fetch_assoc()
引发了异常。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.