How should I store States and Countries?
Option 1) I could create a database table called states, and have ‘id’, ‘state’, and ‘state_abbr’. I could then reference that by ‘id’ in the users table.
Option 2) I could create a PHP array and use that to populate the states drop down menu, and avoid querying the database altogether. The key for the array would be the value inserted in the database for that user.
States don’t change, and so the data should be static. What’s the best way to store this information and why? Wouldn’t a PHP array be faster? Why does it seem like the database is the best way to store it then?
Thoughts?
A wise database designer once told me, “Everything you know about state codes is wrong.”
Given that you’re not likely to know all these things about such a common thing as USPS state codes, it just makes more sense to store them in a table. Tables are easier to maintain at run time than a PHP array is.