function domain_get_primary_table in Domain Access 7.2
Same name and namespace in other branches
- 6.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 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 and default database..
See also
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 259 - Domain bootstrap file.
Code
function domain_get_primary_table($table) {
global $databases;
$db_prefix = isset($databases['default']['default']['prefix']) ? $databases['default']['default']['prefix'] : '';
if (is_string($db_prefix)) {
$table = $db_prefix . $table;
}
elseif (is_array($db_prefix)) {
$table = $db_prefix['default'] . $table;
}
// db_escape_table() relies on a database connection, so we mirror that public
// method here. See DatabaseConnection::escapeTable.
return preg_replace('/[^A-Za-z0-9_.]+/', '', $table);
}