您好,欢迎访问一九零五行业门户网

php计算mysql数据库大小的代码分享

本文主要和大家分享php计算整个mysql数据库大小的方法,这里用mb,kb或者gb的格式返回计算结果。希望能帮助到大家。
function calcfulldatabasesize($database, $db) { $tables = mysql_list_tables($database, $db); if (!$tables) { return -1; } $table_count = mysql_num_rows($tables); $size = 0; for ($i=0; $i < $table_count; $i++) { $tname = mysql_tablename($tables, $i); $r = mysql_query("show table status from ".$database." like '".$tname."'"); $data = mysql_fetch_array($r); $size += ($data['index_length'] + $data['data_length']); }; $units = array(' b', ' kb', ' mb', ' gb', ' tb'); for ($i = 0; $size > 1024; $i++) { $size /= 1024; } return round($size, 2).$units[$i]; } /* ** example: */ // open mysql connection: $handle = mysql_connect('localhost', 'user', 'password'); if (!$handle) { die('connection failed!'); } // get the size of all tables in this database: print calcfulldatabasesize('customer1234', $handle); // --> returns something like: 484.2 kb // close connection: mysql_close($handle);
相关推荐:
php计算整个mysql数据库大小的方法,php计算mysql数据库_php教程
mysql之delete删除记录后数据库大小不变_mysql
php计算整个mysql数据库大小的方法,php计算mysql数据库
以上就是php计算mysql数据库大小的代码分享的详细内容。
其它类似信息

推荐信息