在2个数据库之间共享用户

发布于 2024-10-21 18:04:12 字数 309 浏览 0 评论 0原文

我正在用 PHP 开发这个应用程序。该应用程序将包含一个管理区域,其中还包含员工功能。应用程序的另一部分是面向客户的网站。

行政区域有自己的数据库。面向客户的网站也有自己的数据库。

在管理数据库中,我有一个包含用户的表,我还计划实现 RBAC,以便用户可以拥有角色、权限等。

面向客户的网站还允许客户注册,并将其存储在客户网站数据库的用户表中。

我需要的是能够让员工登录客户网站。他们还需要拥有控制可以修改客户网站的哪些部分以及可以更改客户网站数据库中的哪些行的权限。

实现这一点的最佳方法是什么?

干杯:)

I am developing this application in PHP. The application will consist of an adminstration area which will also contain employee functions. The other part of the application is the customer facing website.

The administration area has its own database. The customer facing website also has its own database.

In the administration database, I have a table with users and I also plan to implement RBAC so that users can have roles, permissions and so on.

The customer facing website also allows customers to register and that's stored in a user table in customer website database.

What I need is to be able to have employees logging on at the customer website. They also need to have permissions which controls which parts of the customer website they can modify and which rows in the customer website database they can change.

What's the best way to implement this?

Cheers :)

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

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

发布评论

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

评论(2

迷爱 2024-10-28 18:04:12

我建议尽可能合并处理相同概念的表(此处为用户)。

这里的问题是数据访问安全,无论您的数据如何存储(一个或两个表,一个或两个数据库)。

使用MySQL(以及许多其他常见的DBMS),您可以:

  • 创建一个MySQL帐户,该帐户只能访问某些表,只能对其执行一些操作(例如,只能选择),只能访问某些列等。

  • 从 MySQL 帐户中隐藏表并仅授予对某个视图的访问权限此表(过滤列/表结果)。

无论您的数据结构是什么,您都需要检查一些员工数据(登录名、密码、权限等),并且您的代码必须使用具有足够权限的 MySQL 帐户。

因此,我建议您将用户保留在一张表中,添加表来描述角色(员工、客户等),并明智地编码。

请记住分别解决数据库设计数据访问安全问题。数据访问安全不应该导致您在数据库设计中做出不合逻辑的选择。

I would recommend to always merge, when possible, tables handling the same concept (Users here).

The problem here is the data access security, no matter how your data is stored (one or two tables, one or two databases).

With MySQL (and many other common DBMS), you can :

  • Create a MySQL account which will have only access to some tables, do only some operations on it (e.g. only SELECT), access only some columns etc.

  • Hide a table from a MySQL account and give only access to a view on this table (filtering columns/table results).

Whatever is your data structure, you will need to check some employee data (login, password, permissions etc.) and your code will have to use a MySQL account with enough privileges for that.

So I would advise you to keep your users in one table, add tables to describe roles (employee, customer, etc.), and code wisely.

Keep in mind to address separately database design and data access security issues. Data access security should not lead you to illogical choices in database design.

や莫失莫忘 2024-10-28 18:04:12

您可以执行以下操作:

$sql = "SELECT * FROM employeedb.employee_user_table WHERE employee_id = '???'";

作为线程启动器的评论问题。对于两个用户表,您可以使用如下解决方案:

  • 创建新表。例如:global_user_table 字段:

    • 用户 ID
    • 通过
    • table_source(真实表源)
    • is_special_user(或类似的东西)
    • additional_field1
    • additional_field2
    • 等等,等等
  • 每次用户登录时,让它检查此表并将table_source存储在会话中,以供以后使用.

You can do something like this:

$sql = "SELECT * FROM employeedb.employee_user_table WHERE employee_id = '???'";

As comment problem from thread starter. For two user tables, you can use solution like this:

  • create new table. eg: global_user_table with field:

    • user_id
    • pass
    • table_source (real table source)
    • is_special_user (or something like that)
    • additional_field1
    • additional_field2
    • etc, etc, etc
  • everytime user login, have it check on this table and store table_source on session, for later usages.

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