-
Notifications
You must be signed in to change notification settings - Fork 0
/
member.php
35 lines (30 loc) · 961 Bytes
/
member.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
//允許跨域存取
header("Access-Control-Allow-Origin: *"); // 允許所有來源
header("Content-Type: application/json; charset=UTF-8");
try {
// 連線 MySQL
if ($_SERVER['HTTP_HOST'] == 'localhost' || $_SERVER['HTTP_HOST'] == '127.0.0.1') {
// 開發環境
require_once("connectPxzoo.php");
} else {
// 生產環境
require_once("connect_chd104g4.php");
}
// SQL 查詢
$sql = "SELECT * FROM member"; // 修改為您的 SQL 查詢
// 準備 SQL 查詢
$member = $pdo->prepare($sql);
// 執行 SQL 查詢
$member->execute();
// 檢查是否有資料
if ($member->rowCount() > 0) {
$memberData = $member->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($memberData);
} else {
echo json_encode(["errMsg" => "查無此資料"]);
}
} catch (PDOException $e) {
echo json_encode(["errMsg" => "執行失敗: " . $e->getMessage()]);
}
?>