You are here: Re: automating the construction of faster queries « PHP SQL « IT news, forums, messages
Re: automating the construction of faster queries

Posted by ZeldorBlat on 05/22/06 18:07

strawberry wrote:
> After reading somewhere in one of these NGs that naming all the fields
> in a query produced faster searches than "SELECT *..." I've rewritten
> my queries as follows:
>
> $table = words;
> $describe = "DESCRIBE $table;";
> $field_array = mysql_query($describe) or die ("Couldn't execute
> query.");
>
> while ($row = mysql_fetch_assoc($field_array))
> {
> $fields .= $row["Field"] . ", ";
> }
> $fields = substr($fields, 0, -2); //trim last comma
>
> echo $fields;
>
> $query = "SELECT $fields FROM $table etc, etc"
>
> This works but looks extremely long-winded. I bet there's a much more
> efficient way of doing this, isn't there?

Yes -- tell it exactly which columns you want. The reason select * is
slow is because you're getting /all/ the columns. If a table has 20
columns and you only need 3, then why ask for all of them?

 

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

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