|
Posted by Martie on 05/22/06 19:39
On 21 May 2006 10:40:20 -0700, 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?
>
Most of tables I work with are pretty static so there's not much change in the
information I'd be looking up. If you are switching from "*" to
"column1,column2, etc." to gain speed, you'd probably lose that with the extra
query you're adding by using the "describe words" command. Instead of just
printing the column names in place of the wildcard "*", you'd be adding another
process to your script which would probably make it run slower.
[Back to original message]
|