found_rows() everytime returns 1

found_rows() everytime returns 1

am 03.05.2006 18:11:15 von andrea azzini

hi to all
I use this query
SELECT SQL_CALC_FOUND_ROWS * FROM prods LIMIT 100,10;

I'd like to know how many rows this query returns without limit, but
using this
select FOUND_ROWS();
the result is everytime 1

You know why?
No other query are processed before the found_rows().
Thanks

--
Andrea

Re: found_rows() everytime returns 1

am 04.05.2006 05:58:16 von christian.jean

Not an answer to your question, but I figured that I'd try and run it
on my server... here is my results.

I'm using: mysql Ver 12.22 Distrib 4.0.24, for pc-linux-gnu (x86_64)

I ran all of these queries in this exact sequence:

If I run 'select * from client;' I get 264 rows
If I run 'select found_rows();' I get the correct value of 264
If I run 'select * from client limit 100,10;' I will get 10 rows
If I run 'select found_rows();' I erroneously get 110

So I guess its pretty much broken... I'll stay away from it!

Jeach!

Re: found_rows() everytime returns 1

am 04.05.2006 09:18:35 von andrea azzini

You haven't use the SQL_CALC_FOUND_ROWS.
In the manual you can find "If the preceding SELECT statement does not
include the SQL_CALC_FOUND_ROWS option, then FOUND_ROWS() may return a
different result when LIMIT is used than when it is not."
If you can, try with this option.

p.s. i use on my server mysql 5.0.18
--
Andrea

Re: found_rows() everytime returns 1

am 04.05.2006 10:28:39 von andrea azzini

mmmhhhh
I ran the queries using the MySQL Query Browser software
(http://www.mysql.com/products/tools/query-browser/)
and the result of found_rows was 1.
I ran the two queries above in a php page and the count of rows was
correct. I have lost many time for this problem :(

--
Andrea

Re: found_rows() everytime returns 1

am 04.05.2006 10:35:30 von andrea azzini

mmmhhhh
I ran the queries using the MySQL Query Browser software
(http://www.mysql.com/products/tools/query-browser/)
and the result of found_rows was 1.
I ran the two queries above in a php page and the count of rows was
correct. I have lost many time for this problem :(

--
Andrea

Re: found_rows() everytime returns 1

am 04.05.2006 12:06:11 von andrea azzini

mmmhhhh
I ran the queries using the MySQL Query Browser software
(http://www.mysql.com/products/tools/query-browser/)
and the result of found_rows was 1.
I ran the two queries above in a php page and the count of rows was
correct. I have lost many time for this problem :(

--
Andrea

Re: found_rows() everytime returns 1

am 04.05.2006 18:36:10 von Bill Karwin

andrea azzini wrote:
> I ran the queries using the MySQL Query Browser software
> (http://www.mysql.com/products/tools/query-browser/)
> and the result of found_rows was 1.

MySQL Query Browser opens a new connection for each statement you
execute. The value returned by FOUND_ROWS() is relevant only during the
current connection. So there is no way to use this function in MySQL
Query Browser; you must use the command-line tool 'mysql'.

FWIW, the same issue happens when trying to use other session-dependent
features in MySQL Query Browser, such as LAST_INSERT_ID() and user
variables.

Regards,
Bill K.