domain_prefix_get_tables

Definition

domain_prefix_get_tables($prefix = NULL)
domain_prefix/domain_prefix.module, line 93

Description

Get the tables with the active prefix

Parameters

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

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;
}