Usage of the phpat (@) symbol _ PHP Tutorial

Source: Internet
Author: User
Usage of the phpat (@) symbol. The following describes its usage. for example, the copy code is as follows: functiondb_connect () connects to the database {@ $ dbmysql_connect (localhost, root, test); if (! $ Db) thrownewExcept The following describes its usage.

For example:

The code is as follows:


Function db_connect () // connect to the database
{
@ $ Db = mysql_connect ('localhost', 'root', 'test ');
If (! $ Db)
Throw new Exception ('failed to connect to the database! Please try again! ');
Mysql_select_db ('book ');
Return $ db;
}


If the connection to the database fails, the previous "@" will be able to suppress the error, that is, it will not display the error, and then throw an exception to display its own exception handling, this is just to make the page viewer invisible. unfriendly pages cannot suppress errors, but can only Suppress display errors! @ Is used in the place where you think an error may occur in the future. @ a space will be placed next to it! It is better to use less, as if to increase the system overhead.

Example: Code: function db_connect () // connect to the database {@ $ db = mysql_connect ('localhost', 'root', 'test'); if (! $ Db) throw new partition t...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.