You are here

function _db_maintenance_list_tables in DB Maintenance 6.2

Same name and namespace in other branches
  1. 8.2 db_maintenance.module \_db_maintenance_list_tables()
  2. 6 db_maintenance.module \_db_maintenance_list_tables()
  3. 7 db_maintenance.module \_db_maintenance_list_tables()

Get a list of all the tables in a database.

Parameters

string $db The name of the database connection to query for tables.:

Return value

array representing the tables in the specified database.

1 call to _db_maintenance_list_tables()
db_maintenance_admin_settings in ./db_maintenance.module
Administration settings

File

./db_maintenance.module, line 85
Optimizes database tables during cron runs.

Code

function _db_maintenance_list_tables($db) {
  $table_names = array();

  // Set the database to query.
  $previous = db_set_active($db);
  if (_db_maintenance_determine_software() == 'mysql') {
    $result = db_query('SHOW TABLES');
  }
  elseif (_db_maintenance_determine_software() == 'pgsql') {
    $result = db_query("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_name");
  }

  // Return to the previously set database.
  db_set_active($previous);
  while ($table_name = db_fetch_array($result)) {
    $table_name = current($table_name);
    $table_names[$table_name] = $table_name;
  }
  return $table_names;
}