How to implement skipping when encountering errors in php
This article mainly introduces php how to achieve error skip, the article is very detailed, has a certain reference value, interested friends must read it!
1. Open the corresponding PHP code file.
2. you can suppress the error by displaying it with the @ error control operator.
Example
Function db_connect () / / Connect to database {@ $db = mysql_connect ('localhost','root','test'); if (! $db) {throw new Exception (' failed to connect to database! Please try again!');} mysql_select_db ('book'); return $db;}
If the connection to the database is not successful, the previous "@" will be able to suppress the error, that is, it will not show the error, and then throw an exception to show the self-defined exception handling. It is recommended to use less, which will increase the system overhead.
The above is all the contents of the article "how to skip errors encountered by php". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!