php取出mysql数据库中所有数据

本文展示了一个使用PHP连接MySQL数据库并获取所有表数据的例子。通过建立数据库连接、获取表名列表,再到显示每个表的内容,文章详细介绍了每一步的操作过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<?php
 header("Content-Type:text/html; charset=utf-8");
 $db_con=new mysqli("localhost","root","psd","ultrax");
 if(mysqli_connect_errno()){
     exit("连接失败".mysqli_connect_error());
 }
 $db_con->query("set names utf8");
 $result=$db_con->query("show tables");
 $tables=array();
while ($row=$result->fetch_row()){
     array_push($tables, $row[0]);
 }
 function show_shuju($sql,$table){
     global $db_con;
     $result=$db_con->query($sql);
     $fields=$result->fetch_fields();
     $ziduan=array();
     foreach ($fields as $field){
         array_push($ziduan, $field->name);
     }
     $fidld_length=count($ziduan);
     echo "<table>";
     echo "<thead>";
     echo "<caption style='color:red'>".$table."</caption>";
     echo "</thead>";
     echo "<tbody>";
     while($assoc=$result->fetch_assoc()){
         echo "<tr>";
         for($i=0;$i<$fidld_length;$i++){
             echo "<td>".$assoc[$ziduan[$i]]."</td>";
         }
         echo "</tr>";
     }
     echo "</tbody>";
     echo "</table>";
 }
 foreach ($tables as $value) {
     $sql="select * from ".$value;
     show_shuju($sql,$value);
 }
 ?>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值