Home > Backend Development > PHP Tutorial > php at(@)符号的用法简介_PHP

php at(@)符号的用法简介_PHP

WBOY
Release: 2016-06-01 12:23:15
Original
1007 people have browsed it

下面介绍一下它的用法.

例如:
复制代码 代码如下:
function db_connect()//连接数据库
{
@$db =mysql_connect('localhost','root','test');
if(!$db)
throw new Exception('连接数据库失败!请重试!');
mysql_select_db('book');
return $db;
}

如果连接数据库不成功的,前面的“@”就能把错误显示给抑制住,也就是不会显示错误,然后再抛出异常,显示自己定义的异常处理,添加这个只是为了让浏览者不看到,不友好的页面,并不能抑制住错误,只能抑制显示错误!@ 用在你觉得以后运行有可能会出现错误的地方 , @后面要来个空格!最好少用,好像增加系统开销.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template