Files
security-book/课堂代码/01-blog开发/v2/test.php
2026-04-25 13:52:04 +08:00

29 lines
783 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// 字符集设置为utf-8
header("Content-Type: text/html; charset=UTF-8");
// 连接mysql数据库
$host = "127.0.0.1";
$dbname = "root";
$dbpassword = "usbw";
$database = "blog";
$port = 3307;
$conn = mysqli_connect($host, $dbname, $dbpassword, $database, $port);
if (!$conn) {
echo "连接失败";
exit;
}
// 获取users表中的所有数据
$sql = "select * from users";
$result = mysqli_query($conn, $sql);
if (!$result) {
echo "查询失败";
exit;
}
// 将查询的数据一行行输出
// mysqli_fetch_assoc函数是将查询的数据以关联数组的形式返回数组的key是字段名value是字段值
while ($row = mysqli_fetch_assoc($result)) {
echo "<p>" . $row["username"] . ":" . $row["email"] . ":" . $row["password"] . "</p>";
}