|
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]
|