Jump to content

unable to override php's default exception Messages


ajoo
Go to solution Solved by QuickOldCar,

Recommended Posts

Hi all !

 

I have been using this snippet below to study exceptions:

<?php

mysqli_report(MYSQLI_REPORT_STRICT);

try {
     $connection = new mysqli('localhos', 'root', '', 'test') ;
} catch (Exception $e ) {
     echo "Server Error";
}

?>

If, as in the snippet, I misspell the localhost, I am unable to override the php's own message. If, on the other hand I just misspell say the database name with the host spelt correctly, it overrides the php's default message. ( Default messages in both examples above being different).

 

with the host name misspelt I receive the following warning:

 

 

Warning: mysqli::mysqli(): php_network_getaddresses: getaddrinfo failed: This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server. in D:\xampp\htdocs\xampp\miscellaneous\exceptions.php on line 6

 

With the host name correct but a wrong database name I get the message defined in the snippet. Namely "Server Error".

 

Kindly help resolve this. 

 

Thanks very much.

Link to comment
Share on other sites

  • Solution

Disable all error reporting either with htaccess, php.ini or at the top per php script.

 

htaccess

php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_value docref_root 0
php_value docref_ext 0

php.ini

error_reporting = off

php scripts, last line helps remove strict errors

error_reporting(E_ALL);
ini_set("display_errors", 1);
ini_set('error_reporting', 30711);
  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.