There must be a easier way to do this:

it prints the size of a mysql database in Megabytes.

$query = mysql_query("SELECT data_length, index_length FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'pvs'");
while($data = mysql_fetch_array($query)){
    $num[] = ($data['data_length'] + $data['index_length']);
}
for($i = 0; $i < count($num); $i++) {
$tot = $num[$i] / 1048576;
}

echo $tot;
Member Avatar
diafol

Try:

$dbname = "pvs";
$r = mysql_query("SELECT table_schema,SUM( data_length + index_length ) / 1048576 AS dbsize FROM information_schema.TABLES WHERE table_schema = '$db_name'");
$d = mysql_fetch_assoc($r);
echo "$dbname DB size = {$d['dbsize']} Mb";
Member Avatar
diafol

OK, we solved?