• Advertisement
Sign in to follow this  

[web] Suppressing MYSQL warnings?

This topic is 3877 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a stored function in MYSQL that does a lookup in a table. Every so often it will get 0 rows returned from a lookup it performs. This is causing a warning to be generated. The occasional 0 rows returned is perfectly normal for this routine, so I'd like to block the warning. The offending sql statement goes something like this: SELECT mycol INTO somevar FROM mytable WHERE id='123'; The row '123' may or may not exist depending on the current state of the db. The problem is that I may need to do thousands of queries and I don't want a flood of meaningless warnings to mess with. I would like to suppress warning 1329 which is the "No Data - zero rows fetched" warning. Is there a way to do this?

Share this post


Link to post
Share on other sites
Advertisement
$rs = @mysql_query("SELECT mycol INTO somevar FROM mytable WHERE id='123';");


The @ will suppress any errors that occur with the query. You can also add that to the other MySQL functions in PHP.

Share this post


Link to post
Share on other sites
That's handy to know, but my problem is that the sql call is being made from within a sql 'create function' routine rather than from php. The call is basicly the same as entering the query from a mysql command prompt.

Share this post


Link to post
Share on other sites
SET sql_warnings=OFF;

Note that this changes the settings on a per-connection basis, so you'll have to do it each time you connect. Additionally it'll kill all warnings; I don't know of a way to selectively disable warnings (and Google didn't turn up anything). To see a full list of things you can screw around with, use SHOW variables; Further reading.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement