Bug #36719 FOUND_ROWS() reports previous after an error
Submitted: 14 May 2008 18:03 Modified: 23 May 2008 15:30
Reporter: John Larsen Email Updates:
Status: Closed
Category:Server: Docs Severity:S3 (Non-critical)
Version:4.1,5.0,5.1,6.0 BK OS:Any
Assigned to: Paul DuBois Target Version:
Triage: D4 (Minor)

[14 May 2008 18:03] John Larsen
Description:
Using PHP mysql_connect()

mysql_query("SELECT 1");  //for instance then
mysql_query("SELECT SQL_CALC_FOUND_ROWS blah FROM blah");  //where this query returns an
error instead of a result
mysql_query("select FOUND_ROWS() as c");   //This returns the result of the previous
query before the error in this case a 1

I don't know if I would call that a bug, but preferably I think a result of 0 would be
preferable?

How to repeat:

mysql_query("SELECT 1");  //for instance then
mysql_query("SELECT SQL_CALC_FOUND_ROWS blah FROM blah");  //where this query returns an
error instead of a result
mysql_query("select FOUND_ROWS() as c");   //This returns the result of the previous
query before the error in this case a 1
[14 May 2008 19:25] Sveta Smirnova
Thank you for the report.

Verified as described. Probably can be considered as documentation request.
[23 May 2008 11:49] Konstantin Osipov
Paul, this is not a bug in the server.
The value of FOUND_ROWS() is reset by the next successful SELECT statement.
I've read the manual article,
http://dev.mysql.com/doc/refman/4.1/en/information-functions.html
and it's sufficient. 
Perhaps it would be enough to add to the manual that beyond the given description the
behaviour of FOUND_ROWS() is unspecified.
[23 May 2008 12:41] Paul DuBois
Changing to Documentation category.
[23 May 2008 15:30] Paul DuBois
Thank you for your bug report. This issue has been addressed in the documentation. The
updated documentation will appear on our website shortly, and will be included in the
next release of the relevant products.

Updated documentation per comment from Konstantin: FOUND_ROWS() behavior undefined except
as described. Also pointed out that it is set for *successful* SELECT statements (to avoid
implying that failed statements set it).