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

Posted by FFMG on 07/26/07 06:14

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 forum http://www.httppoint.com, (Ad revenue sharing).

 

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

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