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 for 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 for diafol

OK, we solved?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.