Name: Don Arnett Date: December 19, 2004 at 22:01:20 Pacific Subject: suppress PHP, mysql warnings OS: linux CPU/Ram: na
Comment:
I'm using PHP and mysql. I'm having a problem figuring out how to handle mysql errors and warnings.
For example, if I have trouble connecting to the database, I know how to check the return from the mysql_connect() function and go on from there to build my page, but php still displays warning messages on the webpage. So the warnings get mixed in with my text.
Is there a way to change this. Maybe a setting in php to not display warning message. I don't want the warning messages, just let me check the return codes!!
Be sure to come back and let us know if our suggestions helped!
Look in your php.ini-file for the section which I copied and pasted below.
Warnings can be surpressed, but fatal errors (like parsing errors) cannot and will crash your script anyway. It is very hard to write good code if you have turned off all the errors, so I suggest you look for a different approach (i.e. post parts of the script wich causes the errors in this forum)
Good luck.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Error handling and logging ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; error_reporting is a bit-field. Or each number up to get desired error ; reporting level ; E_ALL - All errors and warnings ; E_ERROR - fatal run-time errors ; E_WARNING - run-time warnings (non-fatal errors) ; E_PARSE - compile-time parse errors ; E_NOTICE - run-time notices (these are warnings which often result ; from a bug in your code, but it's possible that it was ; intentional (e.g., using an uninitialized variable and ; relying on the fact it's automatically initialized to an ; empty string) ; E_CORE_ERROR - fatal errors that occur during PHP's initial startup ; E_CORE_WARNING - warnings (non-fatal errors) that occur during PHP's ; initial startup ; E_COMPILE_ERROR - fatal compile-time errors ; E_COMPILE_WARNING - compile-time warnings (non-fatal errors) ; E_USER_ERROR - user-generated error message ; E_USER_WARNING - user-generated warning message ; E_USER_NOTICE - user-generated notice message ; ; Examples: ; ; - Show all errors, except for notices ; ;error_reporting = E_ALL & ~E_NOTICE ; ; - Show only errors ; ;error_reporting = E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR ; ; - Show all errors except for notices ; error_reporting = E_ALL; display all errors, warnings and notices
Thanks for the response. I apparently didn't explain myself well enough.
I'm not worried about syntax errors etc. I can write the code so that there are no errors when everything works, but what about if the DB is down when someone accesses the page.
I know how to check the return codes and code my page so that I can display the appropriate messages, etc., but php is also displaying warning messages that appear on my page. I don't want to turn off error return codes, I just want to set php to not display messages. Give me return codes but don't write on my page!!!
Be sure to come back and let us know if our suggestions helped!
Again, the point wasn't to ignore the warnings, but to let my code decide what appears on the screen and not have PHP printing error messages to the screen.
Be sure to come back and let us know if our suggestions helped!
setting in php.ini. I set it to off and the warning messages to appear on the screen. Just what I wanted. The 'error_reporting' would let you have finer control of which error messages appear.
Be sure to come back and let us know if our suggestions helped!
The information on Computing.Net is the opinions of its users. Such
opinions may not be accurate and they are to be used at your own risk.
Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE