NYCPHP Meetup

NYPHP.org

mySQL optimization question.

Nasir Zubair lists at ny-tech.net
Tue May 27 12:37:46 EDT 2003


I was wondering if I have following two pieces of codes. Which one is better
and why.
 
1:
 
$result = mysql_query("SELECT col_name FROM table_name");
$count = mysql_num_rows($result);
 
 
2: 
 
$result = mysql_query("SELECT count(*) FROM table_name");
list($count) = mysql_fetch_row($result);
 
I always though COUNT(*) was better than getting the rows and counting them
via PHP. I need to explain it to someone as to why or why not count(*) is
better than the other method.
 
Any comments?
 
- Nasir




More information about the talk mailing list