Reply to Re: So, SELECT count(*)... or mysql_num_rows(...)

Your name:

Reply:


Posted by ZeldorBlat on 07/26/07 13:18

On Jul 26, 2:14 am, FFMG <FFMG.2ub...@no-mx.httppoint.com> wrote:
> Hi,
>
> I was running a test on a table with 50000 rows.
> When I do:
>
> $sql = "SELECT * FROM TABLE";
> $result = mysql_query($sql);
> $total = 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 = "SELECT count(*) as num FROM TABLE";
> $result = mysql_query($sql);
> $result = mysql_fetch_assoc( $result );
> $total = $result['num'];
>
> Everything works fine.
>
> or is
> $sql = "SELECT FOUND_ROWS() AS num FROM TABLE";
> ..
> even better?
>
> So What is the 'preferred' method of getting a row count?
>
> FFMG
>
> --
>
> 'webmaster forum' (http://www.httppoint.com) | 'webmaster Directory'
> (http://www.webhostshunter.com/) | 'Recreation Vehicle insurance'
> (http://www.insurance-owl.com/other/car_rec.php)
> 'Free URL redirection service' (http://urlkick.com/)
> ------------------------------------------------------------------------
> FFMG's Profile:http://www.httppoint.com/member.php?userid=580
> View this thread:http://www.httppoint.com/showthread.php?t=18782
>
> Message Posted via the webmaster forumhttp://www.httppoint.com, (Ad revenue sharing).

Always use "select count(*)" for this type of thing.

The database doesn't necessarily need to go and actually get all the
rows to figure it out this way. If you "select *" and then ask for
the row count he actually needs to go get all those rows, which is why
you're running out of memory.

[Back to original 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

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