function _prod_check_dbstatus_mysql in Production check & Production monitor 7
Same name and namespace in other branches
- 6 includes/prod_check.admin.inc \_prod_check_dbstatus_mysql()
Helper function to return MySQL detailed status info.
1 call to _prod_check_dbstatus_mysql()
- prod_check_dbstatus in includes/
prod_check.admin.inc - Database status page.
File
- includes/
prod_check.admin.inc, line 872
Code
function _prod_check_dbstatus_mysql($details) {
$db_name = '';
// Feels like there should be a better way of getting the current database
// name.
$db_setting = Database::getConnectionInfo();
foreach ($db_setting as $params) {
if (isset($params['database'])) {
// We get the first name we find.
$db_name = $params['database'];
break;
}
}
// Get detailed status.
$rows = array();
try {
$result = db_query('SHOW STATUS');
foreach ($result as $row) {
$rows[] = array(
$row->Variable_name,
$row->Value,
);
}
} catch (Exception $e) {
}
if ($rows) {
$details['status'] = array(
'title' => t('Detailed status'),
'header' => array(
t('Variable'),
t('Value'),
),
'rows' => $rows,
);
}
// Get all tables.
$rows = array();
try {
// We cannot use the standard db_query with arguments here as the argument
// should NOT be enclosed in quotes.
$result = db_query(sprintf('SHOW TABLES FROM %s', $db_name));
$property = 'Tables_in_' . $db_name;
foreach ($result as $row) {
$rows[] = array(
$row->{$property},
);
}
} catch (Exception $e) {
}
if ($rows) {
$details['tables'] = array(
'title' => t('Tables for active database %name', array(
'%name' => $db_name,
)),
'header' => array(
t('Table'),
),
'rows' => $rows,
);
}
// Get all databases.
$rows = array();
try {
$result = db_query('SHOW DATABASES');
foreach ($result as $row) {
$rows[] = array(
$row->Database,
);
}
} catch (Exception $e) {
}
if ($rows) {
$details['databases'] = array(
'title' => t('Available databases'),
'header' => array(
t('Database'),
),
'rows' => $rows,
);
}
return $details;
}