Supressing MySQL errors
Moderator: General Moderators
-
MarkAshley
- Forum Commoner
- Posts: 34
- Joined: Fri Nov 18, 2005 1:36 am
Supressing MySQL errors
Hi all
I am developing a web app which runs on PHP/MySQL/Apache. If the results of a query include a field with a value of null, mysql_result() returns an invalid result source error. I don't want my users to see the error, as the query returning a null field is not a problem.
In php.ini I have set error_reporting to E_COMPILE_ERROR as this seems to be the least likely to include this error. I also set display_errors to Off. I also added error_reporting(0) to the top of my script. However, the errors still appear.
Is there anything else I need to do in order to stop these MySQL errors from appearing?
Thanks
Mark
I am developing a web app which runs on PHP/MySQL/Apache. If the results of a query include a field with a value of null, mysql_result() returns an invalid result source error. I don't want my users to see the error, as the query returning a null field is not a problem.
In php.ini I have set error_reporting to E_COMPILE_ERROR as this seems to be the least likely to include this error. I also set display_errors to Off. I also added error_reporting(0) to the top of my script. However, the errors still appear.
Is there anything else I need to do in order to stop these MySQL errors from appearing?
Thanks
Mark
Probably something went wrong with the query (e.g. a sql syntax error), therefore the first parameter for mysql_result is not a mysql result resource but FALSE.If the results of a query include a field with a value of null, mysql_result() returns an invalid result source error.
The exact error/warning message for this is
There's no problem fetching a NULL value with mysql_result.Warning: mysql_result(): supplied argument is not a valid MySQL result resource
About error_reporting
Do yourself the favor and switch your error_reporting on (E_ALL), display errors of all kinds and try a different approach to get your data from the database.
Switching off errors during development is the worst thing you can do.
Switching off errors during development is the worst thing you can do.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
-
MarkAshley
- Forum Commoner
- Posts: 34
- Joined: Fri Nov 18, 2005 1:36 am
Thanks for the replies. I made a mistake in my original post. I was using mysql_result() when the error occurred. It occurred when no results were returned from the query so row 0 did not exist, but I tried to assign the value of row 0 to a variable. This is not a problem as an empty result is normal in this application. It just means that a field on the form will be empty instead of containing data.
I am aware of the dangers of turning off errors, but I didn't want my users to be bombarded with irellevant error messages. Adding an @ to the beginning of the mysql_result() functions works perfectly for suppressing these errors.
Thanks very much!
I am aware of the dangers of turning off errors, but I didn't want my users to be bombarded with irellevant error messages. Adding an @ to the beginning of the mysql_result() functions works perfectly for suppressing these errors.
Thanks very much!