connect_error) { die("连接失败: " . $conn->connect_error); } // 构建SQL查询语句 $sql = "SELECT * FROM 首页横幅图片 ORDER BY 序号 ASC"; // 执行查询 $result = $conn->query($sql); if ($result->num_rows > 0) { // 将结果转换为关联数组 $data = $result->fetch_all(MYSQLI_ASSOC); // 输出JSON数据 header('Content-Type: application/json'); echo json_encode($data); } else { // 如果没有匹配的数据 header('Content-Type: application/json'); echo json_encode(array('message' => '没有找到匹配的数据')); } // 关闭数据库连接 $conn->close(); ?>