欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

通过php快速统计某个数据库中每张表的数据量

程序员文章站 2023-12-04 08:01:21
所以自己简单写了几行代码用来实现以上需求 执行结果: 复制代码 代码如下:
所以自己简单写了几行代码用来实现以上需求

执行结果:
通过php快速统计某个数据库中每张表的数据量

复制代码 代码如下:

<?php
$conn=mysql_connect('localhost','root','');
mysql_select_db('数据库',$conn);
$sql="select information_schema.tables.table_name from information_schema. tables where table_schema = '数据库'";
$res=mysql_query($sql);
while ($result = mysql_fetch_assoc($res)) {
$tables[]=$result['table_name'];
};
echo "<table>
<tbody>
<tr>
<td>表名</td>
<td>数据量</td>
</tr>";
foreach ($tables as $k=>$v){
$sql_count="select count(id) as nums,'".$v."' from ".$tables[$k];
$res_count=mysql_query($sql_count);
$result_count = mysql_fetch_assoc($res_count);
echo "<tr><td>".$result_count[$v].'</td><td>'.$result_count['nums'].'</td></tr>';
}
echo "</tbody></table>"
?>