2024年09月02日 建站教程
<?php
// 连接数据库
$conn = mysqli_connect("localhost", "root", "", "test");
if (!$conn) {
die("连接失败: " . mysqli_connect_error());
}
// 查询数据
$sql = "SELECT id, name, email FROM users";
$result = mysqli_query($conn, $sql);
// 输出表格
echo "<table>";
echo "<tr><th>ID</th><th>姓名</th><th>邮箱</th></tr>";
while ($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['email']."</td>";
echo "</tr>";
}
echo "</table>";
// 关闭连接
mysqli_close($conn);
?>
本文链接:http://so.lmcjl.com/news/12103/