当前位置:Gxlcms > PHP教程 > 懂PHP和MYSQL的请进---------请教统计数量

懂PHP和MYSQL的请进---------请教统计数量

时间:2021-07-01 10:21:17 帮助过:18人阅读

原始效果
--------------------------------------------------
数据库总量:
490766329
数据库大小:
25115924452
---------------------------------------------------
要达到的效果
数据库总量:
4.90亿条
数据库大小:
23.39 GB


关键代码

$e=0;
$count=mysql_query("select table_name from information_schema.tables where table_schema='data'");
while($rows=mysql_fetch_array($count)){
$c= $rows['table_name'];
$count_table=mysql_query("select count(*) from $c");
while(@$d=mysql_fetch_array($count_table)){
$e= $e+($d['count(*)']);

}
}


?>

数据库总量:


亿条


占用空间:


23.39GB
后面的GB没定义 请帮忙弄下 谢谢了
参考代码 http://www.douban.com/note/139003240/


回复讨论(解决方案)

只会用笨办法了;

$a = 490766329;$b = 25115924452;echo number_format(floor($a*pow(10, -6))*pow(10, -2),2);echo number_format($b/pow(1024,3),2).'GB';

$sql = "select sum(TABLE_ROWS) as 记录数, sum(DATA_LENGTH+INDEX_LENGTH) as 占用空间 from information_schema.tables where table_schema='data'";$rs = mysql_query($sql);print_r(mysql_fetch_assoc($rs));

人气教程排行