You are here

function systeminfo_display_database_table_content in System Information 6

Same name and namespace in other branches
  1. 5.2 systeminfo.module \systeminfo_display_database_table_content()
  2. 6.2 systeminfo.module \systeminfo_display_database_table_content()
1 string reference to 'systeminfo_display_database_table_content'
systeminfo_menu in ./systeminfo.module
Implementation of hook_menu().

File

./systeminfo.module, line 856
Displays information about the Drupal installation and system environment.

Code

function systeminfo_display_database_table_content() {
  global $db_url;
  $connection = arg(5);
  $table_name = arg(6);
  if (!$connection || !$table_name) {
    drupal_goto('admin/reports/systeminfo/database');
  }
  $databases = !is_array($db_url) ? array(
    'default' => $db_url,
  ) : $db_url;
  if (!isset($databases[$connection])) {
    drupal_goto('admin/reports/systeminfo/database');
  }
  $database = $databases[$connection];
  $db = parse_url($database);
  $database_name = substr($db['path'], 1);
  $header = array();
  $rows = array();
  $limit = variable_get('systeminfo_database_tables_rows', 50);
  db_set_active($connection);
  $result = pager_query("SELECT * FROM " . db_escape_string($table_name), $limit);
  while ($row = db_fetch_array($result)) {
    if (!$header) {
      $header = array_keys($row);
    }
    $row_data = array();
    foreach ($row as $data) {
      $row_data[] = !is_null($data) ? check_plain($data) : theme('placeholder', 'NULL');
    }
    $rows[] = $row_data;
  }
  db_set_active();
  drupal_set_title(t('Content of %databasename-tablename', array(
    '%databasename-tablename' => $database_name . '.' . $table_name,
  )));
  $output = '<p>' . t('View <a href="@structure-table">structure of %tablename</a>.', array(
    '@structure-table' => url('admin/reports/systeminfo/database/structure/' . $connection . '/' . $table_name),
    '%tablename' => $table_name,
  )) . '</p>';
  if ($rows) {
    $output .= theme('table', $header, $rows, array(
      'class' => 'systeminfo',
    ));
    $output .= theme('pager', NULL, $limit);
  }
  else {
    $output .= '<p>' . t('The database table is empty.') . '</p>';
  }
  return $output;
}