Home >Backend Development >PHP Tutorial >懂PHP和MYSQL的请进 ---------请教统计数量

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 14:19:351210browse

原始效果
--------------------------------------------------
数据库总量:
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));

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:关于搜索引擎的问题Next article:php截取中文