I have this is my settings.php file for one (secondary site) site:

$db_prefix = array(
'default' => 'music_',
'users' => 'main_',
'sessions' => 'main_',
'role' => 'main_',
'authmap' => 'main_',
'sequences' => 'main_',
'profile_fields' => 'main_',
'profile_values' => 'main_',
'user_roles' => 'main_',
);
*
* Database URL format:
* $db_url = 'mysql://username:password@localhost/database';
* $db_url = 'pgsql://username:password@localhost/database';
*/
$db_url = 'mysql://username:password@localhost/database';
$db_prefix = 'music_';

-------------------------------------------------
And for the main or first site:
$db_url = 'mysql://username:password@localhost/database';
$db_prefix = 'main_';

If I comment out $db_prefix = 'music_'; the pages go blank and the site will not use the main_ which are the shared tables. I created a user on the music site and it showed up in the music_user table not the main_user. Multisites is working fine but I am unable to share tables. Can anyone help? I am using 5.1. I do have the db_url setup correctly just removed my info for safety.

Thanks!

Comments

mastahl’s picture

and cannot figure out what what I am doing wrong. Any help would be greatly appreciated. Thanks

CloudCuckoo’s picture

Looking at what you posted from settings.php for the secondary site what you've done is uncomment and change the '$db_prefix as array' example. It's the $db_prefix after the comments you needed to change (line 94).

 * To have all database names prefixed, set $db_prefix as a string:
 *
 *   $db_prefix = 'main_';
 *
 * To provide prefixes for specific tables, set $db_prefix as an array.
 * The array's keys are the table names and the values are the prefixes.
 * The 'default' element holds the prefix for any tables not specified
 * elsewhere in the array. Example:
 *
 *   $db_prefix = array(
 *     'default'   => 'main_',
 *     'users'     => 'shared_',
 *     'sessions'  => 'shared_',
 *     'role'      => 'shared_',
 *     'authmap'   => 'shared_',
 *     'sequences' => 'shared_',
 *   );
 *
 * Database URL format:
 * $db_url = 'mysql://username:password@localhost/database';
 * $db_url = 'pgsql://username:password@localhost/database';
 */
 $db_url = 'mysql://username:password@localhost/database';
 $db_prefix = array(
 'default' => 'music_',
 'users' => 'main_',
 'sessions' => 'main_',
 'role' => 'main_',
 'authmap' => 'main_',
 'sequences' => 'main_',
 'profile_fields' => 'main_',
 'profile_values' => 'main_',
 'user_roles' => 'main_',
);

---------------------------------------------
THE MIND: PHENOMENAL COSMIC POWER... in an itty bitty living space

mastahl’s picture

I knew it was something silly. I appreciate it.

What are the tables that need to be shared to only share users and not anything else? So that the user info stays straight?

CloudCuckoo’s picture

The minimum to share only users is

'users'
'sessions'
'authmap'
'sequences'

If you're using profile module and want profiles on both sites you also need to share

'profile_fields'
'profile_values'

Whether or not to share roles and users_roles is up to you. If you're only going to use core roles anonymous and authenticated then I wouldn't bother. If you're going to have broadly the same non core roles on each site
e.g. each site has content editor, store administrator and site administrator roles then I'd share the roles table. And if you're going to have the same users in the same non core roles across both sites then share role and users_roles.

---------------------------------------------
THE MIND: PHENOMENAL COSMIC POWER... in an itty bitty living space

joep.hendrix’s picture

Thanks for your good explanation of the different scenarios!
Very helpfull!

-----------------------------------------
Joep
CompuBase, websites and webdesign

-----------------------------------------
Joep
CompuBase, Dutch Drupal full service agency

karunadave’s picture

Hi Thanks for your post.

I have found that for a new install, where I want to use the db_prefix with some shared tables for users and of course separate tables for most tables, I pre configurer the settings.php file for the $db_prefix as an array, but the installer overwrites the db_prefix, and produces a PHP error on the installer page.

Immediately after this, if I reapply to the settings.php file the db_prefix settings I want, and then refresh the installer page, it installs the the tables the way I want.

Original settings.php

$db_url = 'mysql://username:password@localhost/databasename';
$db_prefix = array(
  'default'   => 'prefix_',
  'authmap'        => 'shared_',
  ...
);

gets overwritten in db_prefix (which is bad), and of course in the db_url connection data (which is good)

Example

$db_url = 'mysql://realusername:realpassword@localhost/realdatabasename';
$db_prefix = '';
  'default'   => 'prefix_',
  'authmap'        => 'shared_',
  ...
);

Immediately I change the settings.php file db_prefix back to the initial, and refresh the drupal install browser page.

$db_url = 'mysql://realusername:realpassword@localhost/realdatabasename';
$db_prefix = array(
  'default'   => 'prefix_',
  'authmap'        => 'shared_',
  ...
);

The install succeeds, with shared tables being 'shared_...' and everything else being the default 'prefix...'.

This also succeeds for the second Drupal site in the same database. It does complain about the shared tables already existing, but after this initial warning the second site works fine too.

mewren’s picture

I am having the same problem with the overwrite. The workaround works for the first site, but not later sites.

Harry Slaughter’s picture

http://devbee.com/user_sequence_gotcha

--
Devbee - Open Source Business Solutions - http://devbee.com/

--
Devbee - http://devbee.net/