settings_domain_prefix.inc in Domain Access 5
File
domain_prefix/settings_domain_prefix.inc
View source
<?php
_drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
_domain_prefix_load();
function _domain_prefix_load($domain = NULL) {
$check = db_result(db_query("SELECT status FROM {system} WHERE name = 'domain_prefix'"));
if ($check > 0) {
if (is_null($domain)) {
$_subdomain = strtolower(rtrim($_SERVER['HTTP_HOST']));
$domain = db_fetch_array(db_query("SELECT domain_id FROM {domain} WHERE subdomain = '%s'", $_subdomain));
}
if (isset($domain['domain_id'])) {
$tables = array();
$prefix = 'domain_' . $domain['domain_id'] . '_';
$result = db_query("SELECT tablename FROM {domain_prefix} WHERE domain_id = %d AND status > 1", $domain['domain_id']);
while ($data = db_fetch_array($result)) {
$tables[] = $data['tablename'];
}
if (!empty($tables)) {
global $db_prefix;
$new_prefix = array();
if (is_string($db_prefix)) {
$new_prefix['default'] = $db_prefix;
$prefix = $db_prefix . $prefix;
}
foreach ($tables as $table) {
$new_prefix[$table] = $prefix;
}
$db_prefix = $new_prefix;
}
}
}
}