Sometimes we want to get the size of the database. In php, it is quite easy to get the size of mysql database. Just you need to copy/paste the following code and replace the database name with your database name
Code to get mysql database size in php:-
<?php
require_once('conn.php');
function getfilesize( $data ) {
// For bytes
if( $data < 1024 ) {
return $data . " bytes";
}
// For kilobytes
else if( $data < 1024000 ) {
return round( ( $data / 1024 ), 1 ) . "k";
}
// For megabytes
else {
return round( ( $data / 1024000 ), 1 ) . " MB";
}
}
$result = mysql_query( "SHOW TABLE STATUS" );
$dbsize = 0;
while( $row = mysql_fetch_array( $result ) ) {
$dbsize = $row[ "Data_length" ] + $row[ "Index_length" ]+$dbsize;
}
echo "The size of the database is " . getfilesize( $dbsize );
//You just need to change the dbname in connection file
?>
So this is the way to Get size of mysql database in php
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment