最合适的回答,由SO网友:Frank P. Walentynowicz 整理而成
将以下代码添加到小部件代码中:
function fileSizeInfo($filesize) {
$bytes = array(\'KB\', \'KB\', \'MB\', \'GB\', \'TB\');
if ($filesize < 1024)
$filesize = 1;
for ($i = 0; $filesize > 1024; $i++)
$filesize /= 1024;
$dbSizeInfo[\'size\'] = round($filesize, 3);
$dbSizeInfo[\'type\'] = $bytes[$i];
return $dbSizeInfo;
}
function databaseSize() {
global $wpdb;
$dbsize = 0;
$rows = $wpdb->get_results("SHOW table STATUS");
foreach($rows as $row)
$dbsize += $row->Data_length + $row->Index_length;
return fileSizeInfo($dbsize);
}
$dbSize = databaseSize();
echo "<b>Database size</b> = {$dbSize[\'size\']} {$dbSize[\'type\']}";