Page 1 of 1

Supressing MySQL errors

Posted: Mon Aug 07, 2006 2:49 pm
by MarkAshley
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

Posted: Mon Aug 07, 2006 3:41 pm
by volka
If the results of a query include a field with a value of null, mysql_result() returns an invalid result source error.
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.
The exact error/warning message for this is
Warning: mysql_result(): supplied argument is not a valid MySQL result resource
There's no problem fetching a NULL value with mysql_result.

About error_reporting

Posted: Mon Aug 07, 2006 3:41 pm
by donvliet
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.

Posted: Mon Aug 07, 2006 4:31 pm
by duk
well i dont advice as i learn in this forum, but for instant solution you can use @mysql_result

using '@' before the function will supreme all errors, but remember if there is a error coz something is wrong...

Posted: Mon Aug 07, 2006 4:37 pm
by Christopher
Just put single quotes around the value so nulls work. MySQL will sort out the type based on the column type.

Posted: Wed Aug 09, 2006 7:05 am
by MarkAshley
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!

Posted: Wed Aug 09, 2006 8:32 am
by onion2k
mysql_result() is the worst, slowest, most awful function in PHP. Use *anything* else.

Posted: Wed Aug 09, 2006 9:45 am
by MarkAshley
What is the alternative?

Posted: Wed Aug 09, 2006 10:00 am
by feyd
mysql_fetch_*