6

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() );
}

1 Answer 1

5

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 @.

Sign up to request clarification or add additional context in comments.

2 Comments

Wouldn't you say a try-catch is more appropriate for this type of error?
PHP errors aren't exceptions -- they're something separate. It's a bit of a wart in the language.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.