在 mysql 数据库中存储 10 个选项的最佳方法是什么?

发布于 2024-08-04 02:06:04 字数 413 浏览 2 评论 0原文

我正在修改我的 PHP 网络的代码以拥有像 wordpress 这样的“用户角色”,这是我到目前为止的计划

0 = 注册的非电子邮件验证用户
1 = 注册并验证的电子邮件
2 = 主持人
3-9 = 还没有
10= admin

在我的 PHP 代码中,我将使用这样的数组来设置角色编号的用途。

$user_role['10']

我正在考虑存储用户在我的 mysql 数据库中拥有的值,这是将 10 个不同角色选项存储为枚举的最佳方法还是有更好的方法或更快的方法?我读到枚举有时并不是最快的。

enum('0','1','2','3','4','5','6','7','8','9','10')

I am modifying my PHP network's code to have "user roles" like wordpress here is my plan so far

0 = registred non email verified user
1 = registed and verified email
2 = moderator
3-9 = nothing yet
10= admin

In my PHP code I will use an array like this that will set what a role number does.

$user_role['10']

I was thinking of storing which value a user has in my mysql DB, would this be the best way to store the 10 different role options as an enum or is there a better way or faster way? I read that enum is not the fastest sometimes.

enum('0','1','2','3','4','5','6','7','8','9','10')

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

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

发布评论

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

评论(2

春花秋月 2024-08-11 02:06:04

我想 INTTINYINT 足以存储用户级别(角色)。您还可以考虑将数字乘以 10,这样您将来就有空间添加更多级别。

I guess INT or TINYINT is enough to store user level (role). Also you may consider multiplting the numbers by 10, so you'll have a space to add more levels in future.

沙与沫 2024-08-11 02:06:04

使用权限/用户级别的位掩码。

请参阅 示例

Use bitmasks for permissions / user levels.

See example.

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