Information for: DEVELOPERS   PARTNERS   SUPPORT

Sharing database tables across a Drupal multisite

You can also configure your multisite installation to share database tables (such as the users, sessions, and profiles tables) across multiple websites.

To share tables from a database across a Drupal multisite, retrieve the full name of the shared database and then assign it using the prefix array, as you would normally. For example, to use the drupal_shared database for users, sessions, and profiles, while using the example database for everything else, enter the following text in your websites’ settings.php files:

<?php
// Use the example database as our default database, but delay connecting.
$conf['acquia_hosting_settings_autoconnect'] = FALSE;
require('/var/www/site-php/mysite/example-settings.inc');

// Use the drupal_shared database for users, sessions, and profiles.
$shared = $databases['drupal_shared']['default']['database'] . '.';
$databases['default']['default']['prefix'] = array(
    'default' => '',
    'authmap' => $shared,
    'profile_fields' => $shared,
    'profile_values' => $shared,
    'permission' => $shared,
    'role' => $shared,
    'sessions' => $shared,
    'users' => $shared,
    'users_roles' => $shared,
);

// Connect to the database.
acquia_hosting_db_choose_active();
?>

Note

If you do not actively use the acquia_hosting_db_choose_active function, you should remove it from your code. This function is set to null when deployed in an environment powered by Acquia Cloud Next technologies.

For Drupal 8+, omit these final lines:

// Connect to the database.
acquia_hosting_db_choose_active();

Note

If you do not actively use the acquia_hosting_db_choose_active function, you should remove it from your code. This function is set to null when deployed in an environment powered by Acquia Cloud Next technologies.