How to skip when php encounters an error

藏色散人
Release: 2023-03-12 19:48:01
Original
2028 people have browsed it

How to implement skipping when php encounters an error: 1. Open the corresponding PHP code file; 2. Display the error and suppress it through the @error control operator.

How to skip when php encounters an error

The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.

php How to skip when encountering an error?

PHP skips errors and continues execution:

@The error control operator can achieve this function. The

@ symbol can ignore errors and has the function of suppressing errors.

For example:

function db_connect()//连接数据库
{
@$db =mysql_connect('localhost','root','test');
if(!$db) {
throw new Exception('连接数据库失败!请重试!');
}
mysql_select_db('book');
return $db;
}
Copy after login

If the connection to the database is unsuccessful, the preceding "@" can suppress the error display, that is, the error will not be displayed, and then an exception will be thrown and displayed. It is recommended to use your own defined exception handling sparingly, as this will increase a certain amount of system overhead.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to skip when php encounters an error. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!