旧版服务端
This commit is contained in:
1 parent
3429c8b402
commit
25bbb5f9c8
971 files changed
+87141
-40
No files matched your search
Executable
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
// 引用配置,建立数据库连接
|
||||
require_once 'ApiConfig.php';
|
||||
$conn = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
|
||||
|
||||
// 检查连接是否成功
|
||||
if ($conn->connect_error) {
|
||||
die(json_encode(["error" => "数据库连接失败"]));
|
||||
}
|
||||
|
||||
// 接收前端传递的 OpenID
|
||||
$received_openid = isset($_GET['openid']) ? $_GET['openid'] : null;
|
||||
|
||||
if ($received_openid) {
|
||||
// 构建 SQL 查询字符串
|
||||
$sql = "SELECT * FROM 用户已购课程 WHERE OpenID = '" . $received_openid . "'" . " ORDER BY `购课日期` DESC";
|
||||
|
||||
// 执行查询
|
||||
$result = $conn->query($sql);
|
||||
|
||||
// 检查查询结果
|
||||
if ($result->num_rows > 0) {
|
||||
// 获取查询结果
|
||||
$data = array();
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$data[] = $row;
|
||||
}
|
||||
// 将结果转换为 JSON 格式并输出
|
||||
echo json_encode(["result" => "拥有课程信息已查询到", "data" => $data]);
|
||||
} else {
|
||||
echo json_encode(["result" => "拥有课程信息未查询到", "data" => null]);
|
||||
}
|
||||
} else {
|
||||
echo json_encode(["error" => "未提供 OpenID"]);
|
||||
}
|
||||
|
||||
// 关闭数据库连接
|
||||
$conn->close();
|
||||
?>
|
||||
Reference in new issue
Block a user