如何使用评级系统创建最佳架构数据库,并在月内提供?

时间:2011-06-25 12:03:11

标签: php mysql database doctrine schema

我将创建数据库MySQL的架构。有用户名,密码等和评级系统,月份可用。 标准它看起来像这样:

id | username | password | january | february | march     | rating1 | rating2| rating3 |
1  | john     |  xxx     | 1       |  0       | 1         |  3      | 3      | 6
2  | amy      |  xxx     | 1       |  1       | 0         |  1      | 6      | 3

如果用户购买商品,则必须添加评级(1,2,3)。如果在约翰中选择2然后评级2 +1

id | username | password | january | february | march     | rating1 | rating2| rating3 |
1  | john     |  xxx     | 1       |  0       | 1         |  3      | 4      | 6
2  | amy      |  xxx     | 1       |  1       | 0         |  1      | 6      | 3
1月,2月(1 - 可用,0 - 不可用)等自己约翰或艾米。

这很好吗?我应该为Januar / feb / march和rating1 / 2/3创建单独的表吗?也许只是为了评级?

2 个答案:

答案 0 :(得分:2)

我不是一个硬核数据库设计师,但一眼就看出这是架构没有规范化。

如果你可以为月创建一个单独的表,评级会更好,请找到下面的示例

d |用户名|密码

1 |约翰| XXX
2 |艾米| xxx

id |月|评价

1 | 1 | 3

MonthID | MONTHNAME

1 |一月

这种sujjestion可能不是您提议的数据库的理想解决方案。

答案 1 :(得分:0)

好的,我知道这已经晚了,但这非常严重!!!

首先使用bcrypt加密密码

第二个NEVER存储未正确加密的密码。你需要一个“盐”来正确地做到这一点。

见这里:http://www.nathandavison.com/posts/view/13/php-bcrypt-hash-a-password-with-a-logical-salt

我不是个骗子,但看起来不错。

至于DB,Prabhakantha的答案看起来不错,但可能不完全合适。

用户

id | username | password | salt

1  | john     | xxx      | blah
2  | amy      | xxx      | ughh

评分

id | month_id | rating
1  | 1        | 3

id | month   | year
1  | January | 1990

我知道在ruby on rails世界中我会用多态关联建模。看看这是如何工作的:http://railscasts.com/episodes/154-polymorphic-association

是的,它是轨道上的视频,但它适用于此处。