forked from lesterchan/wp-dbmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase-manager.php
110 lines (105 loc) · 3.55 KB
/
database-manager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
### Check Whether User Can Manage Database
if(!current_user_can('manage_database')) {
die('Access Denied');
}
### Variables Variables Variables
$base_name = plugin_basename('wp-dbmanager/database-manager.php');
$base_page = 'admin.php?page='.$base_name;
$backup = array();
$backup_options = get_option('dbmanager_options');
$backup['date'] = current_time('timestamp');
$backup['mysqldumppath'] = $backup_options['mysqldumppath'];
$backup['mysqlpath'] = $backup_options['mysqlpath'];
$backup['path'] = $backup_options['path'];
### Get MYSQL Version
$sqlversion = $wpdb->get_var("SELECT VERSION() AS version");
?>
<?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
<!-- Database Information -->
<div class="wrap">
<h2><?php _e('Database', 'wp-dbmanager'); ?></h2>
<h3><?php _e('Database Information', 'wp-dbmanager'); ?></h3>
<br style="clear" />
<table class="widefat">
<thead>
<tr>
<th><?php _e('Setting', 'wp-dbmanager'); ?></th>
<th><?php _e('Value', 'wp-dbmanager'); ?></th>
</tr>
</thead>
<tr>
<td><?php _e('Database Host', 'wp-dbmanager'); ?></td>
<td><?php echo DB_HOST; ?></td>
</tr>
<tr class="alternate">
<td><?php _e('Database Name', 'wp-dbmanager'); ?></td>
<td><?php echo DB_NAME; ?></td>
</tr>
<tr>
<td><?php _e('Database User', 'wp-dbmanager'); ?></td>
<td><?php echo DB_USER; ?></td>
</tr>
<tr class="alternate">
<td><?php _e('Database Type', 'wp-dbmanager'); ?></td>
<td>MYSQL</td>
</tr>
<tr>
<td><?php _e('Database Version', 'wp-dbmanager'); ?></td>
<td>v<?php echo $sqlversion; ?></td>
</tr>
</table>
</div>
<p> </p>
<div class="wrap">
<h3><?php _e('Tables Information', 'wp-dbmanager'); ?></h3>
<br style="clear" />
<table class="widefat">
<thead>
<tr>
<th><?php _e('No.', 'wp-dbmanager'); ?></th>
<th><?php _e('Tables', 'wp-dbmanager'); ?></th>
<th><?php _e('Records', 'wp-dbmanager'); ?></th>
<th><?php _e('Data Usage', 'wp-dbmanager'); ?></th>
<th><?php _e('Index Usage', 'wp-dbmanager'); ?></th>
<th><?php _e('Overhead', 'wp-dbmanager'); ?></th>
</tr>
</thead>
<?php
$no = 0;
$row_usage = 0;
$data_usage = 0;
$index_usage = 0;
$overhead_usage = 0;
$tablesstatus = $wpdb->get_results("SHOW TABLE STATUS");
foreach($tablesstatus as $tablestatus) {
if($no%2 == 0) {
$style = '';
} else {
$style = ' class="alternate"';
}
$no++;
echo "<tr$style>\n";
echo '<td>'.number_format_i18n($no).'</td>'."\n";
echo "<td>$tablestatus->Name</td>\n";
echo '<td>'.number_format_i18n($tablestatus->Rows).'</td>'."\n";
echo '<td>'.format_size($tablestatus->Data_length).'</td>'."\n";
echo '<td>'.format_size($tablestatus->Index_length).'</td>'."\n";;
echo '<td>'.format_size($tablestatus->Data_free).'</td>'."\n";
$row_usage += $tablestatus->Rows;
$data_usage += $tablestatus->Data_length;
$index_usage += $tablestatus->Index_length;
$overhead_usage += $tablestatus->Data_free;
echo '</tr>'."\n";
}
echo '<tr class="thead">'."\n";
echo '<th>'.__('Total:', 'wp-dbmanager').'</th>'."\n";
echo '<th>'.sprintf(_n('%s Table', '%s Tables', $no, 'wp-dbmanager'), number_format_i18n($no)).'</th>'."\n";
echo '<th>'.sprintf(_n('%s Record', '%s Records', $row_usage, 'wp-dbmanager'), number_format_i18n($row_usage)).'</th>'."\n";
echo '<th>'.format_size($data_usage).'</th>'."\n";
echo '<th>'.format_size($index_usage).'</th>'."\n";
echo '<th>'.format_size($overhead_usage).'</th>'."\n";
echo '</tr>';
?>
</table>
</div>