Home  >  Article  >  Backend Development  >  How to prevent errors in php

How to prevent errors in php

藏色散人
藏色散人Original
2020-08-12 09:12:283722browse

How to set up php to prevent error reporting: 1. Add the "@" symbol before the error statement; 2. Before the start of the php file, add the statement "error_reporting(0)"; 3. Open php.ini file, just turn off the error reporting function.

How to prevent errors in php

Recommended: "PHP Video Tutorial"

Shielding PHP errors

Method 1: @ Shielding method

@ is a symbol that suppresses errors in PHP. Even if you enable the error reporting function, just add the @ symbol before the error statement to shield the error message.

PHP Manual Reference: Error Control Operator

Code Example:

@mysql_connect() OR die('connect mysql failed');

Method Two: error_reporting Shielding Method

Before the php file starts, we can Add the sentence error_reporting(0); this function means to set the error level of PHP and return the current level. 0 means disabling error reporting.

PHP Manual Reference: error_reporting

Code example:

<?php
// 关闭所有PHP错误报告
error_reporting(0);
?>

Method three: display_errors shielding method

This method should be the most thorough solution method, because the first two methods can only act on a single line or a single file, while this one acts on all php files. Open the php.ini file and search for display_errors = on. The default should be on, which means the error reporting function is enabled. Change it to off.

PHP Manual Reference: Runtime Configuration

Example:

php.ini
display_errors = off;

The above is the detailed content of How to prevent errors in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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