You are here

function dba_tables_optimize in Database Administration 5

1 call to dba_tables_optimize()
dba_admin_tables_optimize in ./dba.module
MySQL only: optimize the selected table(s).

File

./dba.module, line 1058
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_tables_optimize() {
  $tables = dba_get_active_tables(0);
  $quantity = empty($tables) ? 0 : count($tables);
  if (!$quantity) {
    drupal_set_message(t('You must select the tables to optimize.'), 'error');
    drupal_goto('admin/build/database');
  }
  else {
    drupal_set_title(t('Optimizing %table', array(
      '%table' => format_plural($quantity, 'table', 'tables'),
    )));
    $query = 'OPTIMIZE TABLE ' . implode(', ', $tables) . ';';
    drupal_set_message(check_plain($query));
    $result = db_query($query);
    $header = array(
      t('Table'),
      t('Operation'),
      t('Message type'),
      t('Message text'),
    );
    $rows = array();
    while ($row = db_fetch_object($result)) {
      $rows[] = array_map('check_plain', (array) $row);
    }
    $output = theme('table', $header, $rows);
  }
  return $output;
}