php,,
“<?php // 连接数据库 $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "myDB"; // 创建连接 $conn = new mysqli($servername, $username, $password, $dbname); // 检测连接 if ($conn>connect_error) { die("连接失败: " . $conn>connect_error); } // SQL查询语句 $sql = "SELECT id, name, age FROM users"; $result = $conn>query($sql); if ($result>num_rows > 0) { // 输出数据 echo "<table border='1'>"; echo "<tr><th>ID</th><th>姓名</th><th>年龄</th></tr>"; while($row = $result>fetch_assoc()) { echo "<tr><td>" . $row["id"]. "</td><td>" . $row["name"]. "</td><td>" . $row["age"]. "</td></tr>"; } echo "</table>"; } else { echo "0 结果"; } $conn>close(); ?>
原创文章,作者:未希,如若转载,请注明出处:https://www.kdun.com/ask/765219.html
本网站发布或转载的文章及图片均来自网络,其原创性以及文中表达的观点和判断不代表本网站。如有问题,请联系客服处理。
发表回复