You are here

function domain_prefix_get_tables in Domain Access 5

Same name and namespace in other branches
  1. 6.2 domain_prefix/domain_prefix.admin.inc \domain_prefix_get_tables()

Get the tables with the active prefix

Parameters

$prefix: The table prefix used with this domain. Optional.

2 calls to domain_prefix_get_tables()
domain_prefix_configure_form in domain_prefix/domain_prefix.module
FormsAPI for generating the configuration form
domain_prefix_form in domain_prefix/domain_prefix.module
The table prefixing page for a domain.

File

domain_prefix/domain_prefix.module, line 93
Interface for selective table prefixing for use with Domain Access. For this module to work correctly, you will need to follow the INSTALL.txt instructions for editing your settings.php file.

Code

function domain_prefix_get_tables($prefix = NULL) {

  // Check for default prefix settings.
  if (empty($prefix)) {
    $prefix = domain_prefix_get_prefix();
  }
  switch ($GLOBALS['db_type']) {
    case 'pgsql':
      if (empty($prefix)) {
        $result = db_query("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'");
      }
      else {
        $result = db_query("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name LIKE '{$prefix}%%'");
      }
      break;
    default:

      // MySQL and MySQLi implementation.
      if (empty($prefix)) {
        $result = db_query("SHOW TABLES");
      }
      else {
        $result = db_query("SHOW TABLES LIKE '{$prefix}%%'");
      }
      break;
  }
  $tables = array();
  $disallow = domain_prefix_disallow();
  while ($data = db_fetch_array($result)) {

    // Chop table prefixes.
    $str = current($data);
    if (!empty($prefix)) {
      $str = preg_replace('/' . $prefix . '/', '', $str, 1);
    }
    if (!in_array($str, $disallow) && substr($str, 0, 7) != 'domain_') {
      $tables[$str]['tablename'] = $str;
      $tables[$str]['module'] = domain_prefix_module_lookup($str);
    }
  }

  // Sort them by module
  uasort($tables, '_domain_prefix_sort');
  return $tables;
}