[nycphp-talk] mySQL optimization question.
Sexton, David
David.SextonJr at ubspw.com
Tue May 27 12:41:57 EDT 2003
I would say count() does not pull the data back with it, which makes it
significantly faster when returning a large result set.
-----Original Message-----
From: Nasir Zubair [mailto:lists at ny-tech.net]
Sent: Tuesday, May 27, 2003 12:38 PM
To: NYPHP Talk
Subject: [nycphp-talk] mySQL optimization question.
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
--- Unsubscribe at http://nyphp.org/list/ ---
More information about the talk
mailing list