When I add "display_errors = off" to my php.ini file, I still get some php errors displayed.
BEFORE adding display_errors = off to my php.ini file I was getting full paths, etc displayed (a lot of info. not intended to be seen by a user). AFTER putting display_errors = off in my php.ini file I get much less error info. displayed, however I still get the following error: "Sorry, there was an error: Access denied for user 'username'@'localhost' to database 'mydatabase'. The "Sorry, there was an error" is my custom connect_error die text, and that is all I would like to be displayed. But rendering the username and database I'd like to avoid. Is there something else I need to add to my php.ini file, or is this maybe a function of using connect_error and die in my php code? My LAMP website host does not allow me access to .htaccess and some other config. files. But I do have my own php.ini file I can edit.
Once I get display_error working the way I want I'd like to add log_errors & error_log to my php.ini file so I can log php errors for debugging.
Here is my line in php.ini:
display_errors = off
Here is my check connection code in my php files (in case it helps):
if ($con->connect_error) {
die("Sorry, there was an error: " . $con->connect_error);
}
I expected display_errors = off in my php.ini to give me a blank screen during execution, or only to display "Sorry, there was an error" which would be my preference. Any comments suggestions appreciated. Thank you.
UPDATE: After reading the comments I received to my original post I have attempted to modify some code and add some code.
I added the following line of code just before establishing the mysql db connection so that mysql errors get reported in my php errors log:
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
I then added the following lines to my php.ini so that all errors do not display but get written to a php error log:
error_reporting = E_ALL
display_errors = off
log_errors = on
error_log = ../logs/my_php_error_log
I completely commented out my "$con->connect_error" code (below) since all mysql/php errors now get logged to a file anyway, which I check often. NOTE: If NOT checking the connection is not good practice, please let me know:
/*
if ($con->connect_error) {
die("Sorry, there was an error.");
}
*/
All the above changes I made based on what I learned from comments to my original post, and to the more in-depth information I read at the links provided by those that commented. Thank you.