Access shared database tables on different server

Events happening in the community are now at Drupal community events on www.drupal.org.
ivan zugec's picture

Hi,

I have been working on setting up a multisite + single sign on site, I did this by adding the following to the settings.php.

$db_url = 'mysqli://username:password@localhost/databasename';
$db_prefix = array(
    'default' => '',
    'authmap' => 'shared.',
    'role' => 'shared.',
    'sessions' => 'shared.',
    'users' => 'shared.',
);

It's working fine if all the databases are on the same server.

But is there a way of telling Drupal to connect to a different mysql server to access the authmap, role, sessions and users tables?

Something like this??:

$db_url['default'] = 'mysqli://username:password@localhost/databasename';
$db_url['shared'] = 'mysqli://username:password@192.168.0.1/user_shared';

Thanks

Comments

If you're using another db

rpsu's picture

If you're using another db ('shared') you need to switch to this database BEFORE you can run queries to this database. I guess this is not possible, since you would need to switch server/connection always while needing to get stuff from shared-tables.

See this db_set_active api.

--
Perttu Ehn

Possibly now available in Drupal 7

tebb's picture

I realise that this is now an old issue, but for anyone looking to do something similar ...

In the Drupal 7 settings.php file, there's an array of database connection settings, so this may now be possible.

This is the comment from the file:

  • Database settings:
  • The $databases array specifies the database connection or
  • connections that Drupal may use. Drupal is able to connect
  • to multiple databases, including multiple types of databases,
  • during the same request.

Also

Multisite

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: