如何使用评级系统创建最佳模式数据库并在月份内可用?

发布于 2024-11-17 12:15:46 字数 736 浏览 0 评论 0原文

我将创建数据库 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 - 可用,0 - 不可用)等设置自己为约翰或艾米。

这好吗?我应该为一月/二月/三月和 rating1/2/3 创建单独的表吗?也许只是为了评分?

i will create schema the database MySQL. There are username, password etc and rating system and available in month.
Standard it looks like this:

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

if a user buys article then must add a rating (1,2,3). if chose 2 in John then rating2 +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

january, february (1 - available, 0 - not available)etc set himself John or Amy.

this is good? Should I create separate tables for Januar/feb/march and rating1/2/3? Maybe only for rating?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

假扮的天使 2024-11-24 12:15:46

我不是一个核心数据库设计者,但乍一看,这是模式没有标准化。

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

d |用户名 |密码

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

id |月 |评分

1 | 1 | 3个

月ID |月份名称

1 |一月

然而,这个假设可能不是您提议的数据库的理想解决方案。

im not a hard core database designer but at a glance this is schema is not normalized.

if you can create a separate table for month and rating would be better please find the below sample

d | username | password

1 | john | xxx
2 | amy | xxx

id | month | rating

1 | 1 | 3

MonthID | MonthName

1 | January

How ever this sujjestion may not be the ideal solution for your proposed database.

剑心龙吟 2024-11-24 12:15:46

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

首先使用 bcrypt 加密密码,

其次永远不要存储未正确加密的密码。你需要“盐”才能正确地做到这一点。

请参阅此处: http: //www.nathandavison.com/posts/view/13/php-bcrypt-hash-a-password-with-a-logic-salt

我不是 php 人员,但它看起来不错。

至于 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

是的,这是一个关于 Rails 的视频,但它适用于这里。

OK I know this is late but this is very serious!!!

First use bcrypt for encrypting passwords

Second NEVER store a password that is not encrypted properly. You need a "salt" to do this correctly.

See here: http://www.nathandavison.com/posts/view/13/php-bcrypt-hash-a-password-with-a-logical-salt

I'm not a php guy but it looks good.

As for the DB, Prabhakantha's answer looks OK but might not be complete suitable.

Users

id | username | password | salt

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

ratings

id | month_id | rating
1  | 1        | 3

Months

id | month   | year
1  | January | 1990

I know in the ruby on rails world I would model this with a polymorphic association. Take a look how that works here: http://railscasts.com/episodes/154-polymorphic-association

Yes it is a video on rails but it applies here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文