|
Posted by Rik on 07/26/07 13:20
On Thu, 26 Jul 2007 08:14:09 +0200, FFMG <FFMG.2ubxux@no-mx.httppoint.co=
m> =
wrote:
>
> Hi,
>
> I was running a test on a table with 50000 rows.
> When I do:
>
> $sql =3D "SELECT * FROM TABLE";
> $result =3D mysql_query($sql);
> $total =3D mysql_num_rows(result);
>
> I get a 'run out of memory error', (the limit is set low on the test
> server).
>
> But when I do:
>
> $sql =3D "SELECT count(*) as num FROM TABLE";
> $result =3D mysql_query($sql);
> $result =3D mysql_fetch_assoc( $result );
> $total =3D $result['num'];
>
> Everything works fine.
>
> or is
> $sql =3D "SELECT FOUND_ROWS() AS num FROM TABLE";
> ..
> even better?
>
> So What is the 'preferred' method of getting a row count?
If you don't need the rows themselves, keep use of resources at a low by=
=
using a COUNT() construct. If you do need all the rows, use =
mysql_num_rows(), underneath the surface it is essentially the same as =
FOUND_ROWS(), with the added bonus of getting an integer straight back.
-- =
Rik Wasmus
Navigation:
[Reply to this message]
|