You are here: Re: So, SELECT count(*)... or mysql_num_rows(...) « PHP Programming Language « IT news, forums, messages
Re: So, SELECT count(*)... or mysql_num_rows(...)

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация