Home >Backend Development >PHP Problem >How to prevent errors in php
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.
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!