Shared database with prefix

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

I will now set up a large site with about 10 subdomain. I have decided to have all the pages independently, but would like to share some tables in the database. I only use a database with different prefix.
Main Site prefix -> kjel_
Subdomain prefix -> bas_, fot_ etc.
How do I fix this in settings.php?

I've never done this before, and have read many different posts, but hoping for a detailed answer that's easy to understand.

Has a post here, http://drupal.org/node/782680 , but think I just want to share some tables, because the sites will have different modules enabled.

Comments

Sharing like this?

Ole Martin's picture

Will it be like this on the page that uses "bas_" as prefix? My mainsite are using "kjel_" as prefix.

$db_prefix = array(
'default' => 'bas_',
'users' => 'kjel_',
'sessions' => 'kjel_',
'role' => 'kjel_',
'authmap' => 'kjel_',
);

Sharing like this?

White_Owl's picture

yes. If you want to use shared tables (users, sessions, role and authmap) you should set in the variable $db_prefix these tables, as you post above. Then put $db_prefix variable in the settings.php. Script settings.php can be situated in each site folder or in the default folder.

After that you don't need to install these tables for other sites.
In modules, in the sql queryes you should use {table_name}.

P.S. Variable $db_prefix should be situated under $db_url and be shure that you replace or delete string with $db_prefix = '';

Sorry for my english ;)

Your English is fair. But I

Ole Martin's picture

Your English is fair.
But I do not understand this:

In modules, in the SQL Query you use Hubble (TABLE_NAME).

P.S. Variable $ db_prefix Hubble ask situated under $ db_url and pray That shure you replace or delete string with $ db_prefix ='';

I have copied a finished site in all my subdomain and intended to edit the "settings.php" afterwords.

After That you do not need two install These tables for Other sites.
Have I to delete, in the the database, the old tables that are being shared with main database? (in "bas_" --> delete users, role, etc.)
I hope you understand what I mean.

Another question, if I'm logged on to one side, I am logged in all pages?
And thanks for the help

And thanks for the help

White_Owl's picture

But I do not understand this

If you don't write modules for your site you don't need to understand this sentence

Have I to delete, in the the database, the old tables that are being shared with main database? (in "bas_" --> delete users, role, etc.)
I hope you understand what I mean.

Yes you may delete these tables, but if you want transfer users from these sites you need to backUp table (users) and insert data from backUp into shared table for users.

Another question, if I'm logged on to one side, I am logged in all pages?

If you need to one authenticated process for each site (You logged in on some site of your multisite scope) in the settings file you should uncomment variable $cookie_domain and put into this variable your main domai

For example
example.com - main domain

Thanks

Ole Martin's picture

You are an angel ;-D
It works fine now.

It comes slowly to me :-D

Ole Martin's picture

I understod this : $ db_prefix =''; . Its under the line;
$db_url = 'mysql://username:password@localhost/databasename';

Now I get shared users, but not;
'sessions' => 'kjel_',
'role' => 'kjel_',
'authmap' => 'kjel_',

But the users are most importen. Have to import about 2 600 users from old site.

It comes slowly to me :-D

White_Owl's picture

Your $ db_prefix array should look like this

kjel_ - main site
bas_ - subdomain

$ db_prefix = array(
'default' => 'bas_',
'sessions' => 'kjel_',
'role' => 'kjel_',
'authmap' => 'kjel_',
'users' => 'kjel_',
);

Multisite

Group organizers

Group notifications

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