0

I have a problem referencing another database as a prefix in my settings.php file.I have a master-site[mysite.local] and a slave [sub.local].Both of them are having separate database.I need to check the users table of the master-site as well as the users table of the slave site ,when a user tries to authenticate to the slave which is sub.local.I tried adding the following in the settings.php file of the slave

$databases = array (
  'default' => 
  array (
    'default' => 
    array (
      'database' => 'sub_drupal', //Database for the slave site
      'username' => 'root',
      'password' => '',
      'host' => 'localhost',
      'port' => '',
      'driver' => 'mysql',
      'prefix' => array(
                'default'   => 'sub_drupal.',
                'users'     => 'study.', //parent database
                'sessions'  => 'study.',
                'role'      => 'study.',
                'authmap'   => 'study.',
                'users_roles'   => 'study.',
            ),
    ),
  ),
);

But now it authenticates users only on the parent database.Is it not possible to authenticate users present in the slave database sub_drupal and also in the parent database study.Hope someone could help me with this.Thanks

1
  • 1
    Prefixes are for situations when you have shared database. Of course you will have problem using them to access another DB, as this is simply not what they are for, and thus it's impossible. That's pretty much all to it.
    – Mołot
    Commented Jan 4, 2014 at 16:22

1 Answer 1

0

You have the format wrong for two databases you need something like this:

$databases = array(
  'default' => array(
    'default' => array(
      'database' => 'd7',
      'username' => 'root',
      'password' => 'root',
      'host' => '127.0.0.1',
      'port' => '',
      'driver' => 'mysql',
      'prefix' => '',
    ),
  ),
  'db2' => array(
    'default' => array(
      'database' => 'd7_parent',
      'username' => 'root',
      'password' => 'root',
      'host' => '127.0.0.1',
      'port' => '',
      'driver' => 'mysql',
      'prefix' => '',
    ),
  ),
);

You can then use db_set_active('db2'); to change the connection and begin querying the second database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.