Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the trigger error function in PHP?

Tags:

php

mysql

Is it okay to use the trigger_error function when the site is live?

Example below.

// Make the connection:
$dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

if (!$dbc) {
    trigger_error ('Could not connect to MySQL: ' . mysqli_connect_error() );
}
like image 850
KimGIL Avatar asked Jul 07 '11 01:07

KimGIL


1 Answers

As long as you are not displaying errors on screen (display_errors = Off) in php.ini, it is wise to use trigger_error() in your script. It will cause an error message to be written to the error log.

I will add that it is generally not good practice to use the @ for error suppression. Problems with mysqli_connect() will be written to the error log as well, if you leave off the @.

like image 79
Michael Berkowski Avatar answered Oct 04 '22 03:10

Michael Berkowski