AkiShankar
AkiShankar

Reputation: 332

sharing tables from different databases in drupal 7 for a multisite

I am building a drupal multisite, say childone and childtwo. Both have their separate databases. Now the requirement is to share some of the tables, eg. a user created in site childone must have the same access permissions in site childtwo also. Can please anyone suggest me with the proper Stepwise solution ?

Regards

Upvotes: 1

Views: 2577

Answers (1)

Webdrips
Webdrips

Reputation: 265

You need to use table prefixes, and settings.php explains how to accomplish this:

 * You can optionally set prefixes for some or all database table names
 * by using the 'prefix' setting. If a prefix is specified, the table
 * name will be prepended with its value. Be sure to use valid database
 * characters only, usually alphanumeric and underscore. If no prefixes
 * are desired, leave it as an empty string ''.
 *
 * To have all database names prefixed, set 'prefix' as a string:
 * @code
 *   'prefix' => 'main_',
 * @endcode
 * To provide prefixes for specific tables, set 'prefix' as an array.
 * The array's keys are the table names and the values are the prefixes.
 * The 'default' element is mandatory and holds the prefix for any tables
 * not specified elsewhere in the array. Example:
 * @code
 *   'prefix' => array(
 *     'default'   => 'main_',
 *     'users'     => 'shared_',
 *     'sessions'  => 'shared_',
 *     'role'      => 'shared_',
 *     'authmap'   => 'shared_',
 *   ),
 * @endcode

So for your example, for your childone site's settings.php, you'd have something like the following:

'prefix' => array(
  'default'    => 'childone_',
  'user'       => 'shared_',
  'sessions'   => 'shared_',
  'role'       => 'shared_',
  'permission' => 'shared_',
);

And for childtwo's settings.php, it's very similar:

'prefix' => array(
  'default'    => 'childtwo_',
  'user'       => 'shared_',
  'sessions'   => 'shared_',
  'role'       => 'shared_',
  'permission' => 'shared_',
);

All tables will be prefixed with either childone_ or childtwo_ except the shared ones, which will be prefixed with shared_ (or whatever you want) after running the installation.

Upvotes: 3

Related Questions