You are here

function _db_maintenance_list_tables in DB Maintenance 7

Same name and namespace in other branches
  1. 8.2 db_maintenance.module \_db_maintenance_list_tables()
  2. 6.2 db_maintenance.module \_db_maintenance_list_tables()
  3. 6 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.

2 calls to _db_maintenance_list_tables()
db_maintenance_admin_settings in ./db_maintenance.admin.inc
Administration settings
db_maintenance_optimize_tables in ./db_maintenance.module
Perform the maintenance.

File

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

Code

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

  // Set the database to query.
  $previous = db_set_active($db);
  if (db_driver() == 'mysql') {
    $result = db_query("SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'", array(), array(
      'fetch' => PDO::FETCH_ASSOC,
    ));
  }
  elseif (db_driver() == 'pgsql') {
    $result = db_query("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_name", array(), array(
      'fetch' => PDO::FETCH_ASSOC,
    ));
  }

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