开发者

sharing database tables across multiple drupal instance, different db user accounts

I have multiple drupal instances install and would like to share the user and session table from one instance across all my other sites.I place the proper prefix in the settings.php file $db_prefix = array( 'default' => 'db1.', 'sessions' => 'db2.', 'users' => 'db2.', );

Db1 and db2 have its own db user account. I provide the user acccount and credential in the settings.php file as well. $db_url = array( 'default' => 'mysql://user1:password@localhost/db1', 'users' => 'mysql://user2:password@localhost/db2', );

but when drupal is accessing db2, it doesnt know to use the db2 credential to access the user table on db2. I keep on using the default. I also tried using the name of the db and site name of db2 instead of "user" in the $db_url 开发者_StackOverflowbut wasnt successful.

Is there a way of telling drupal to use another account when accessing db2 in the settings file. I know i can just assign user1 on db1 access to the user table on db2 in mysql but would prefer not to if this can be done in settings.php


You can not.

There are for example queries which join {node} and {user} like this:

SELECT n.*, u.name FROM {node} n INNER JOIN {user} u ON u.uid = n.nid

Even using different databases can be problematic and isn't really what the $db_prefix is supposed to be used.

So, you have two options:

  • Create a common user for both databases.

  • If you can't do that (for example, because your hosting environment has a 1:1 mapping between users and databases), move them to the same database but use a different prefix. For example 'site1_' and 'site2_'.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜