I have often seen on here the advice to avoid SELECT * in SQL queries. In terms of making MySQL queries in PHP, if I do actually want the result to contain every column is there any disadvantage in using SELECT * rather then typing out all the column names?
You could always use an array and do something like the following:
implode(", ", array_keys($data))
that way you can control what columns are read in by the HTML form or by some other means.
if you ever add another column to the table, then “select star” will automatically pick it up, and your code may not handle the results properly
but there’s no technical reason why coding all the column names is better than “select star” if you do really want all columns
It is also a question of readable code.
When you only write select *, you do not know what you are retrieving. You have to look at the table structure in your database management tool first.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.