Files
YelayMaths/服务端/API/已弃用ApiGetWebPageContent.php
T
2026-09-29 13:39:36 +08:00

42 lines
1.1 KiB
PHP
Executable File

<?php
// 引用配置,建立数据库连接
require_once 'ApiConfig.php';
$conn = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
// 检查连接是否成功
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
// 获取前端传入的页码
if (isset($_GET['page'])) {
$pageNumber = $_GET['page'];
// 构建SQL查询语句
$sql = "SELECT * FROM 网页数据 WHERE 网页id = '$pageNumber' ORDER BY 顺序id 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' => '没有找到匹配的数据'));
}
} else {
// 如果未提供页码参数
header('Content-Type: application/json');
echo json_encode(array('message' => '未提供页码参数'));
}
// 关闭数据库连接
$conn->close();
?>