Drupal 共享表,但来自另一个数据库 [英] Drupal shared tables, but from another database

查看:14
本文介绍了Drupal 共享表,但来自另一个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含数百个站点的 Drupal 多站点设置.我想让一些表格共享(例如横幅和角色),这样我就不必在更改横幅时更新数百个站点(例如).

I have a Drupal Multisite set up with hundreds of sites. I want to make some tables shared (like banners, and roles) so I don't have to update hundreds of sites when changing a banner (for example).

我知道这可以在 settings.php 中使用这些字符串来完成:

I know this can be done using these strings in settings.php:

$db_url = 'mysql://user:pwd@localhost/example_db';

$db_prefix = array(
     'default'   => '',
     'users'     => 'subsite2_',
     'sessions'  => 'subsite2_',
     'authmap'   => 'subsite2_',
);

但是...如果我也有多个数据库设置怎​​么办?我有一个包含所有共享表的数据库..所以在那个数据库中,我有 Banners 表 - 我希望所有其他网站都可以使用.

But ... what if I have a multiple database setup as well? I have one database that holds all shared tables .. So in that database, I have the Banners table - that I want to have all the other sites to use.

多数据库设置的原因是因为整个多站点设置由数百个站点组成(到今年年底将达到数千个)..所以每个数据库只包含大约 20-40 个站点..我怀疑很多这些表可以共享..

The reason for a multiple database setup is because the whole multisite setup consists of hundreds of sites (and will be thousands by the end of this year) .. so every database only holds about 20-40 sites.. I suspect a lot of these tables can be shared..

希望有人能帮忙.谢谢!

hope someone can help. thanks!

马可

推荐答案

一个演练来设置这样的东西.它旨在仅共享用户数据,但该原则可以扩展到或多或少的所有表.请注意,它通过不仅(或根本不)预先添加表名称前缀,而且/仅使用点表示法添加数据库选择器,在表前缀逻辑上使用技巧",例如someDatabase.someTable.所以我不确定这将如何转换为 PostgreSQL 后端.此外,这意味着您仍然只能使用单个数据库服务器,因为 (AFAIK) 没有机制可以在单个 Drupal 实例中使用两个不同的数据库连接.

There is a walkthrough to setup something like this. It aims at sharing only the user data, but the principle can be extended to more or less all tables. Note that it uses a 'trick' on the table prefixing logic by prepending not only (or not at all) a table name prefix, but also/only a database selector using the dot notation, e.g. someDatabase.someTable. So I'm not sure how this would translate to a PostgreSQL backend. Also, it means that you're still restricted to a single database server, as there is (AFAIK) no mechanism to use two different database connections in a single Drupal instance.

作为替代方案,您可以尝试通过某种复制/镜像功能将共享表映射"到不同的数据库实例,从而从数据库引擎方面找到解决方案.这样你就可以使用标准的 Drupal 多站点设置,在 Drupal 的背后"共享表.不过,不确定这如何/是否可行,以及这会对锁定和其他并发问题产生什么影响.

As an alternative, you might try to find a solution from the database engine side of things by 'mapping' your shared tables into the different database instances via some kind of replication/mirroring feature. That way you could use the standard Drupal multisite setup, doing the sharing of tables 'behind the back' of Drupal. Not sure how/if this would work and what consequences this would have on locking and other concurrency issues, though.

这篇关于Drupal 共享表,但来自另一个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆