PHP循环输出指定数据库中的表名及行数等相关信息

后端开发   发布日期:2023年05月16日   浏览次数:442

PHP循环输出指定数据库中的表名及行数等相关信息,第一步获取指定数据库中的表名,生成数组。

  1. $sql_status=" SHOW TABLE STATUS FROM 数据库名";
  2. if ($result=$mysqli->query($sql_status)){
  3. while ($rs=$result->fetch_array()){ //用数组
  4. $tables_row[]=$rs;
  5. }
  6. }else{
  7. echo "Error";
  8. exit;
  9. }

将数据库中的表名列表数组,用PHP循环输出显示出数据库中数据表的信息

  1. <table width="100%">
  2. <thead>
  3. <tr>
  4. <td colspan="9" align="center" style="font-size:24px;" >数据库优化及状态信息</td>
  5. </tr>
  6. </thead>
  7. <tr>
  8. <td width="12%" height="65" align="center" ><strong> 表的名<br />
  9. Name</strong></td>
  10. <td width="9%" height="65" align="center" ><strong> 存储引擎 <br />
  11. Engine</strong></td>
  12. <td width="7%" height="65" align="center" ><strong> 行数 <br />
  13. Rows</strong></td>
  14. <td width="13%" height="65" align="center" ><strong> 数据文件的长度 <br />
  15. Data_length</strong></td>
  16. <td width="11%" height="65" align="center" ><strong> 索引长度 <br />
  17. Index_length</strong></td>
  18. <td width="11%" height="65" align="center" ><strong> Auto_increment</strong></td>
  19. <td width="16%" height="65" align="center" ><strong>Update_time</strong></td>
  20. <td width="11%" height="65" align="center" ><strong> 字符集和整序 <br />
  21. Collation</strong></td>
  22. <td width="10%" height="65" align="center" ><strong> 评注<br />
  23. Comment</strong></td>
  24. </tr>
  25. <?
  26. //print_r($tables_row);
  27. $i=0;
  28. foreach($tables_row as $value_row){
  29. $mysqli->query ("optimize table ".$value_row[0]." ");//优化各个表
  30. $i++;
  31. ?>
  32. <tr>
  33. <td height="35" align="center" ><?=$value_row[0]?></td>
  34. <td height="35" align="center" ><?=$value_row[1]?></td>
  35. <td height="35" align="center" ><?=$value_row[4]?></td>
  36. <td height="35" align="center" ><?=$value_row[6]?></td>
  37. <td height="35" align="center" ><?=$value_row[8]?></td>
  38. <td height="35" align="center" ><?=$value_row[10]?></td>
  39. <td height="35" align="center" ><?=$value_row[12]?></td>
  40. <td height="35" align="center" ><?=$value_row[14]?></td>
  41. <td height="35" align="center" ><?=$value_row[17]?></td>
  42. </tr>
  43. <?
  44. }
  45. ?>
  46. </table>


以上就是PHP循环输出指定数据库中的表名及行数等相关信息的详细内容,更多关于PHP循环输出指定数据库中的表名及行数等相关信息的资料请关注九品源码其它相关文章!