'缺少客户ID参数'], JSON_UNESCAPED_UNICODE); exit; } // 引入根目录的数据库配置文件 require_once __DIR__ . '/config.php'; // 确保配置变量存在 if (!isset($host) || !isset($username) || !isset($password) || !isset($database)) { http_response_code(500); echo json_encode([ 'error' => '配置文件加载失败', 'message' => '无法读取数据库配置信息' ], JSON_UNESCAPED_UNICODE); exit; } // 配置变量重命名,确保兼容性 $dbname = $database; try { $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, $password); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // 查询指定ID的VIP客户 $stmt = $pdo->prepare(" SELECT id, customer_name, phone, car_model, car_number, email, birthday, notes, is_active FROM vip_customers WHERE id = ? AND is_active = 1 "); $stmt->execute([$id]); $vipCustomer = $stmt->fetch(PDO::FETCH_ASSOC); if ($vipCustomer) { echo json_encode($vipCustomer, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); } else { http_response_code(404); echo json_encode(['error' => 'VIP客户不存在'], JSON_UNESCAPED_UNICODE); } } catch(PDOException $e) { http_response_code(500); echo json_encode([ 'error' => '数据库连接失败', 'message' => $e->getMessage() ], JSON_UNESCAPED_UNICODE); } ?>