简体   繁体   English

具有两个不同名称的MYSQL表

[英]MYSQL table with two different names

I am integrating two systems, moodle and zen-cart. 我正在集成两个系统,即moodle和zen-cart。 Each system has its own table for storing user data. 每个系统都有自己的表来存储用户数据。 I need both systems to access the same table for customers. 我需要两个系统都可以为客户访问同一张表。 Moodle has a table called mdl_users. Moodle有一个名为mdl_users的表。 Zen-cart has a table called customers. Zen-cart的桌子叫客户。 The tables contain similar data but with different field names: 这些表包含相似的数据,但具有不同的字段名称:

mdl_users fields:
id, username, password, firstname, lastname, email, etc....

customers fields:
customers_id, customers_nick, customers_password, customers_firstname, customers_lastname, customers_email_address, etc...

There are hundreds of queries in each system pointing at these tables (in a not well encapsalated way). 每个系统中都有数百个指向这些表的查询(以一种不太简洁的方式)。

Is there a way to point one table at the other, meaning all calls to the customers table will be pulled from the mdl_users table (with field name relations specified)? 有没有一种方法可以将一个表指向另一个表,这意味着对客户表的所有调用都将从mdl_users表(指定了字段名称关系)中提取? I'm not looking to re-write all several hundred queries, but rather set something up once (or call it once per DB call) that automatically does this. 我不是要重写所有数百个查询,而是要设置一次(或每次DB调用一次)自动执行此操作的东西。

Hoped for example result: 希望例如结果:

This query (from the zen-cart system): 此查询(来自zen-cart系统):

Select customers_password from customers where customers_id = :id

Actually returns the results as if it had run: 实际返回结果,就好像它已经运行过一样:

select password from mdl_user where id = :id

(edit/addition) mdl_users.id is the primary key field for the moodle system. (编辑/添加)mdl_users.id是Modle系统的主键字段。 (Unique, indexed, autonumbered). (唯一,索引,自动编号)。 customers.customers_id is the same for the zen-cart system. customer.customers_id与zen-cart系统相同。

Any solution would have to maintain consistency of the primary key numbers as inserts and updates are made. 任何解决方案都必须在进行插入和更新时保持主键号的一致性。

You can use Triggers to do that, search for sql triggers. 您可以使用触发器来执行此操作,搜索sql触发器。 This can make a call from one table to another, i mean you can program the trigger in order to recieve Moodle query and generate a query for zen-cart table. 这可以从一个表到另一个表进行调用,我的意思是您可以对触发器进行编程,以便接收Moodle查询并生成针对zen-cart表的查询。

Which is the "master" system? 哪个是“主”系统? Are users added from both Zen Cart and Moodle, or only from one (or from a different source)? 是从Zen Cart和Moodle中添加用户,还是仅从一个(或从其他来源)添加用户?

I don't think there's a way to do this using only sql, though as suggested before, a view could be a partial solution. 我认为没有办法仅使用sql来执行此操作,尽管如前所述,视图可能是部分解决方案。 I don't see how you could make sure "inserts" work as they should, if only because of data that you could have in one system but not in the other. 我看不到如何确保“插入”按其应有的方式工作,即使仅仅是因为您可以在一个系统中拥有数据而在另一个系统中却没有。

Moodle provides a few ways in which it is possible to use an external system to synchronise users from : "external database authentication" is the first one that I can think of, but in this case, I would probably fork it (auth/db) to make a new plugin that would actually update Zen Cart's db with Moodle's new/updated users (if users can be added in Moodle). Moodle提供了几种使用外部系统来同步用户的方法:“外部数据库身份验证”是我想到的第一个方法,但是在这种情况下,我可能会分叉它(auth / db)制作一个新插件,该插件实际上将与Moodle的新用户/更新用户(如果可以在Moodle中添加用户)一起更新Zen Cart的数据库。

I don't know enough about Zen Cart to suggest something on that side (though there doesn't seem to be any "user/auth plugins"), but it would be worth investigating. 我对Zen Cart的了解不足,无法在这方面提出建议(尽管似乎没有任何“用户/身份验证插件”),但是值得进行调查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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