NYCPHP Meetup

NYPHP.org

[nycphp-talk] mySQL optimization question.

Malcolm, Gary gmalcolm at professionalcredit.com
Tue May 27 12:56:03 EDT 2003


oh yeah,
	try $count = mysql_result("SELECT count(col_name) FROM
table_name");

for a one-liner... 

> -----Original Message-----
> From: Malcolm, Gary [mailto:gmalcolm at professionalcredit.com]
> Sent: Tuesday, 27 May, 2003 9:51 AM
> To: NYPHP Talk
> Subject: RE: [nycphp-talk] mySQL optimization question.
> 
> 
> 1. don't use count(*) because mysql will pull all fields for 
> every record...
> 	use $result = mysql_query("SELECT count(col_name) FROM 
> table_name");
> 
> 2. db's are optimized for this query so their return is like greased
> lightening :)
> 
> 3. let the db do the work!
> 
> 
> > -----Original Message-----
> > From: Nasir Zubair [mailto:lists at ny-tech.net]
> > Sent: Tuesday, 27 May, 2003 9:38 AM
> > 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/ ---
> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20030527/07a59a17/attachment.html>


More information about the talk mailing list