function systeminfo_display_database in System Information 5.2
Same name and namespace in other branches
- 6 systeminfo.module \systeminfo_display_database()
- 6.2 systeminfo.module \systeminfo_display_database()
Menu callback of page 'Database'.
1 string reference to 'systeminfo_display_database'
- systeminfo_menu in ./
systeminfo.module - Implementation of hook_menu().
File
- ./
systeminfo.module, line 707 - Displays information about the Drupal installation and system environment.
Code
function systeminfo_display_database() {
global $db_url;
drupal_add_css(drupal_get_path('module', 'systeminfo') . '/systeminfo.css');
$output = '<p>' . t('Information about the database server.') . '</p>';
$databases = !is_array($db_url) ? array(
'default' => $db_url,
) : $db_url;
foreach ($databases as $connection => $database) {
db_set_active($connection);
$db = parse_url($database);
$output .= '<h3>' . t('Database connection: %connection', array(
'%connection' => $connection,
)) . '</h3>';
// Database tables
$tables_display = variable_get('systeminfo_database_tables_display', 'none');
if ($tables_display == 'all' || $tables_display == 'except' || $tables_display == 'listed') {
$tables_tables = variable_get('systeminfo_database_tables_tables', '');
$tables_rows = variable_get('systeminfo_database_tables_rows', 50);
$header = array(
t('Name'),
t('Rows'),
array(
'data' => t('Operations'),
'colspan' => '2',
),
);
$rows = array();
$result = NULL;
if ($db['scheme'] == 'mysql' || $db['scheme'] == 'mysqli') {
$result = db_query("SHOW TABLES");
}
elseif ($db['scheme'] == 'pgsql') {
$result = db_query("SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname NOT IN ('pg_catalog', 'information_schema', 'pg_toast') ORDER BY tablename");
}
else {
$rows[] = array(
array(
'data' => t('Database type is not supported.'),
'colspan' => '4',
),
);
}
while ($var = db_fetch_array($result)) {
$table_name = current($var);
if ($tables_display == 'all') {
$display = TRUE;
}
elseif ($tables_display == 'except') {
$pattern = '/^(' . preg_replace(array(
'/(\\r\\n?|\\n)/',
'/\\\\\\*/',
), array(
'|',
'.*',
), preg_quote($tables_tables)) . ')$/';
$display = !preg_match($pattern, $table_name);
}
elseif ($tables_display == 'listed') {
$pattern = '/^(' . preg_replace(array(
'/(\\r\\n?|\\n)/',
'/\\\\\\*/',
), array(
'|',
'.*',
), preg_quote($tables_tables)) . ')$/';
$display = preg_match($pattern, $table_name);
}
if ($display) {
$table_name_link = $table_name;
$table_rows = db_result(db_query("SELECT COUNT(*) FROM " . $table_name));
$table_content = l(t('View content'), 'admin/logs/systeminfo/database/content/' . $connection . '/' . $table_name);
$table_structure = l(t('View structure'), 'admin/logs/systeminfo/database/structure/' . $connection . '/' . $table_name);
$rows[] = array(
$table_name_link,
$table_rows,
$table_content,
$table_structure,
);
}
}
$fieldset = array(
'#type' => 'fieldset',
'#title' => t('Database tables'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#value' => theme('table', $header, $rows, array(
'class' => 'systeminfo',
)),
);
$output .= theme('fieldset', $fieldset);
}
// Statement: SHOW STATUS
if ($db['scheme'] == 'mysql' && variable_get('systeminfo_database_mysql_show_status_display', 0) || $db['scheme'] == 'mysqli' && variable_get('systeminfo_database_mysqli_show_status_display', 0)) {
$rows = array();
$result = db_query("SHOW STATUS");
while ($var = db_fetch_array($result)) {
$header = array();
$row = array();
foreach ($var as $var_key => $var_value) {
$header[] = $var_key;
$row[] = $var_value;
}
$rows[] = $row;
}
$fieldset = array(
'#type' => 'fieldset',
'#title' => t('SQL statement: SHOW STATUS'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#value' => theme('table', $header, $rows, array(
'class' => 'systeminfo systeminfo_width50',
)),
);
$output .= theme('fieldset', $fieldset);
}
// Statement: SHOW TABLE STATUS
if ($db['scheme'] == 'mysql' && variable_get('systeminfo_database_mysql_show_table_status_display', 1) || $db['scheme'] == 'mysqli' && variable_get('systeminfo_database_mysqli_show_table_status_display', 1)) {
$rows = array();
$result = db_query("SHOW TABLE STATUS");
while ($var = db_fetch_array($result)) {
$header = array();
$row = array();
foreach ($var as $var_key => $var_value) {
$header[] = $var_key;
$row[] = $var_value;
}
$rows[] = $row;
}
$fieldset = array(
'#type' => 'fieldset',
'#title' => t('SQL statement: SHOW TABLE STATUS'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#value' => theme('table', $header, $rows, array(
'class' => 'systeminfo',
)),
);
$output .= theme('fieldset', $fieldset);
}
// Statement: SHOW VARIABLES
if ($db['scheme'] == 'mysql' && variable_get('systeminfo_database_mysql_show_variables_display', 0) || $db['scheme'] == 'mysqli' && variable_get('systeminfo_database_mysqli_show_variables_display', 0)) {
$rows = array();
$result = db_query("SHOW VARIABLES");
while ($var = db_fetch_array($result)) {
$header = array();
$row = array();
foreach ($var as $var_key => $var_value) {
$header[] = $var_key;
$row[] = $var_value;
}
$rows[] = $row;
}
$fieldset = array(
'#type' => 'fieldset',
'#title' => t('SQL statement: SHOW VARIABLES'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#value' => theme('table', $header, $rows, array(
'class' => 'systeminfo systeminfo_width50',
)),
);
$output .= theme('fieldset', $fieldset);
}
// Statement: SHOW ALL
if ($db['scheme'] == 'pgsql' && variable_get('systeminfo_database_pgsql_show_all_display', 0)) {
$rows = array();
$result = db_query("SHOW ALL");
while ($var = db_fetch_array($result)) {
$header = array();
$row = array();
foreach ($var as $var_key => $var_value) {
$header[] = $var_key;
$row[] = $var_value;
}
$rows[] = $row;
}
$fieldset = array(
'#type' => 'fieldset',
'#title' => t('SQL statement: SHOW ALL'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#value' => theme('table', $header, $rows, array(
'class' => 'systeminfo',
)),
);
$output .= theme('fieldset', $fieldset);
}
}
db_set_active();
return $output;
}