I recently installed Drupal with a multi-site configuration (following http://drupal.org/getting-started/6/install/multi-site). The settings for my main drupal database are in sites/default/settings.php, the settings for my subdomain1 database are in sites/subdomain1.example.com/settings.php, etc...

I have a script that returns all the node types contained in a drupal database. Essentially:

$results = db_query('select distinct type as type from node');

It returns the types contained in the main drupal database (the one I refer to in sites/default/settings.php), the problem is that I want the types contained in a subdomain Drupal database (ex: the one referred in sites/subdomain1.example.com/settings.php).

Can you help me with that?


For record, I found a solution to my problem. I make at the beginning of my script the following assignment:

$_SERVER['HTTP_HOST'] = 'subdomain1.example.com';

It works now.

I found that adding the HTTP_HOST was not enough. bootstrap.inc fails to find the right sub-site unless the SCRIPT_NAME has a leading slash in it. This wasn't the case by default for me running php scripts from command line.

So to get this to work I had to add a:

$_SERVER['SCRIPT_NAME'] = '/'.'myscriptname.php';

Thanks, those were the 2 server variables that made my script work HTTP_HOST & SCRIPT_NAME.

A more Drupaly way in D7+: https://drupal.org/node/2080819