Page 1 of 1
Record Column Order and SELECT *
Posted: Fri Jun 20, 2003 10:24 am
by Gleeb
Just a quick question, I could probably find out using google or something, but, I intend to use an MD5 hash of a table to check someone's cookie is valid (yes, I'm using othermethods too).
'SELECT * from `table`;' - would the order of columns change at all? I.E. Appear in an unpredetermined order? I should probably sort the array by keyname or something, to ensure that the order is consistant... or randomise the order once a day (to reduce ease of cracking)...
Anyway, I hope you can figure out what I'm asking

Posted: Fri Jun 20, 2003 11:38 am
by releasedj
Presuming you rusing MySQL: The columns in a table remain the same unless there's an ALTER TABLE statement issued that changes it.
key
Posted: Fri Jun 20, 2003 2:38 pm
by phpScott
If you have a key field on the table with maybe an autoIncrement or a unique key the just add a ORBER BY clause to your sql and you will always get the same order with any new additions on the end.
I know I have had to do this several times because the order had to remain constant.
phpScott
Posted: Fri Jun 20, 2003 3:30 pm
by releasedj
I think Gleeb was talking about the order of the columns not the rows.
Posted: Fri Jun 20, 2003 7:52 pm
by fractalvibes
I think you are always better off specifying the columns you want rather than select * - a good habit to get into.
select colM
, colR
, colB
, colD
from sometable
guarantees that you get the columns in the order you specify. If the resulting rows need to be in a specific order, add an Order By clause
as you need.
Not sure about MySQL, but most databases have some sort of catalog tables that contain metadata about the database and you can find out the physical order of how the columns are stored in each row in a table...
Phil J.
Posted: Mon Jun 23, 2003 7:15 am
by Gleeb
Thanks for your help
