简体   繁体   中英

Store data in MySQL or a PHP file?

I am working on a project and I ended up with the table below:

+---------------+--------------+------+-----+--------------------+-------+
| Field         | Type         | Null | Key | Default            | Extra |
+---------------+--------------+------+-----+--------------------+-------+
| id            | int(11)      | NO   | MUL | NULL               |  A_I  |
| user _id      | int(11)      | NO   |     | NULL               |       |
| info          | varchar(255) | NO   |     | NULL               |       |
| country       | tinyint(3)   | NO   |     | NULL               |       |
| date_added    | timestamp    | NO   |     | 0000-00-00 00:00:00|       |
+---------------+--------------+------+-----+--------------------+-------+

Because I wanted to avoid storing countries as varchar all the time I thought I should use number IDs instead. My question is, would it be better to store the country IDs in a table where I would give a name to each one of them or do that in a php file? Countries won't change or anything. It will be a list of around 100 countries.

Thanks!

Use a seperate country table.

countries table
---------------
id
name

Then you can relate to the country ID in your table. That way you make sure only countries from your list are added and you don't need to store strings everywhere and you can easily change country names or addnew ones.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM