wake689
January 11, 2022, 10:52pm
1
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?
Thank you.
1 Like
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.
r937
January 12, 2022, 5:45am
3
only maintainability
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
4 Likes
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.
3 Likes
system
Closed
April 13, 2022, 4:14pm
6
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.