You are here

function domain_get_primary_table in Domain Access 6.2

Same name and namespace in other branches
  1. 7.2 domain.bootstrap.inc \domain_get_primary_table()

Escape the names of the default tables for variable lookups.

There are a few cases where we must directly query data from the primary site's database. Due to table prefixing and Domain Prefix, we must ensure that we are querying the correct table.

When using this function, you should insert the $table result directly into your query string, or use token replacement '%s' syntax. Do not enclose the table name in brackets {}, as that defeats the purpose of this function.

Parameters

$table: The name of the base table to lookup.

Return value

A query-safe table name pointing to the primary domain.

See also

_domain_conf_load_primary()

4 calls to domain_get_primary_table()
domain_conf_domain_bootstrap_full in domain_conf/domain_conf.module
Implements hook_domain_bootstrap_full().
_domain_bootstrap in ./domain.bootstrap.inc
Calls individual bootstrap phases.
_domain_bootstrap_modules_get in ./domain.bootstrap.inc
Retrieves the value of the variable 'domain_bootstrap_modules' from the {variable} table. This function does not use Drupal's variable system.
_domain_conf_load_primary in domain_conf/domain_conf.module
Load the variables from the primary domain.

File

./domain.bootstrap.inc, line 235
Domain bootstrap file.

Code

function domain_get_primary_table($table) {
  global $db_prefix;
  if (is_string($db_prefix)) {
    $table = $db_prefix . $table;
  }
  else {
    if (is_array($db_prefix)) {
      if (!empty($db_prefix[$table])) {
        $table = $db_prefix[$table] . $table;
      }
      else {
        if (!empty($db_prefix['default'])) {
          $table = $db_prefix['default'] . $table;
        }
      }
    }
  }
  return db_escape_table($table);
}