I use select * from table as a praxis.
The author of
http://parseerror.com/sql/select*isevil.html
,Ryan Flynn disagrees with that.
Advantages of using select *
Renaming columns takes less effort. You have to modify less code.
Adding columns is the same, you just add a column in the database,then you can use it.
I dont have to read the contents of a comma list.
Ryan Flynns article
statement: "Self documentation lost" when you see a select * statement, how many columns and in which order?
answer: It doesnt matter how many columns there are as long as the execution time doesnt suffer noticeably. By you. It doesnt matter what other people sais. If execution time seems ok for you, then its ok. The order never matters, since you never access the recordset using $rec[34] anyway. People did in 1998. Instead you use column names like $rec['foo']. I have written a wrapper which I use to fetch data from the database. I namely hate to read sql. It should never have been invented. My wrapper uses mysql_fetch_assoc, then a routine automatically creates an object $rec which I can use $rec->foo on to access the column foo.
The self documentation for the data is the database itself.
statement: "Size matters"
answer: The discussion about size tends to be a performance discussion. I dont think thats a big deal mostly and performance is something I think about when I have to. Not before. If it would be a problem, I could adapt. You use mysql_unbuffered_query instead of mysql_query and php doesnt have to save all data that the query resulted in into a big memory block. Letting this be a NIC discussion however seems to be ridiculous. In most of cases, the data will not travel along the network anyway. If you use a multi host environment, things differ slightly. But on the other hand, why having tables with that many columns? Thats EVIL if you ask me.
statement: "Out of order"
answer: Well, as mentioned before, you dont access recordsets using integers but strings. I can consider using $rec[0] if I know there is only one nameless column, but else, I use column names. Writing code that is dependent of the order of columns is adding an unsound dependence in your code.
måndag 31 januari 2011
Prenumerera på:
Kommentarer till inlägget (Atom)
Inga kommentarer:
Skicka en kommentar