How to switch table prefix in a module in Drupal 6? I have multiple sites setup on a single MySQL database in Drupal 6. The sites each have their own prefix, such as site1_, site2_, etc. I'm wondering how I can switch the current table prefix inside of a module to check the variables on each site. For example, I want to check the preprocess_css variable on every site by looping through each sites settings file and running variable_get('preprocess_css') and get the variable for each site. I can get the table prefix and get the variable using db_query on the variables table, but I know there has to be a way to set the current table prefix inside a module so I can just run variable_get inside a loop with each table prefix. Does anyone know how this can be done?
The prefix is stored as one of the variables in the settings.php file, all of which are made global early on in the page build process.

That in mind, you can do something as easy as:

$GLOBALS['db_prefix'] = 'db1_';
print variable_get('site_name', 'default'); // Site name from first set of tables

$GLOBALS['db_prefix'] = 'db2_';
print variable_get('site_name', 'default'); // Site name from second set of tables


Bear in mind that this change won't persist across page loads so you'll need to do your processing in a single load, or implement some sort of system to track which prefix you should currently be using.