You are here

function dba_get_tables in Database Administration 5

Return all tables in active database as array.

Related topics

4 calls to dba_get_tables()
dba_auto_backup in ./dba.module
dba_database_overview_form in ./dba.module
dba_get_active_tables in ./dba.module
Figure out what table(s) are currently selected.
theme_dba_database_overview_form in ./dba.module

File

./dba.module, line 1283
Allows administrators direct access to their Drupal database. Written by Jeremy Andrews <jeremy@kerneltrap.org>, June 2004. PostgreSQL functionality provided by AAM <aam@ugpl.de> Major security audit, porting, and maintenance by Derek…

Code

function dba_get_tables() {
  global $db_prefix;
  static $table_list = array();
  if ($table_list) {

    // Cache copy so function can be called multiple times efficiently.
    return $table_list;
  }
  if (_is_mysql()) {
    $result = db_query('show tables');
  }
  else {
    $result = db_query('SELECT DISTINCT tabname as Table FROM {drupal_system_catalog}');
  }
  while ($tables = db_fetch_object($result)) {
    foreach ($tables as $db => $table) {
      if (!$db_prefix) {
        $table_list[$table] = $table;
      }
      elseif (is_array($db_prefix)) {
        foreach ($db_prefix as $prefix) {
          $prefix = isset($db_prefix[$table]) ? $db_prefix[$table] : $db_prefix['default'];
          if (preg_match("/^({$prefix})/", $table)) {
            $table_list[$table] = $table;
            break;
          }
        }
      }
      elseif (preg_match("/^({$db_prefix})/", $table)) {
        $table_list[$table] = $table;
      }
    }
  }
  return $table_list;
}