Files
kngil_home/kngil/bbs/adm_use_history.php
2026-01-30 17:20:52 +09:00

41 lines
1.3 KiB
PHP

<?php
// 1. DB 연결
require_once 'db_conn.php';
header('Content-Type: application/json');
try {
// JS의 URLSearchParams에서 보낸 키값과 일치시켜야 합니다.
$p_member_id = $_POST['member_id'] ?? '';
$p_user_nm = $_POST['user_nm'] ?? '';
$p_dept_nm = $_POST['dept_nm'] ?? '';
// 2. 프로시저 호출
// PostgreSQL 함수 호출 시 파라미터가 비어있으면 전체 조회가 되도록 설계됨
$stmt = $pdo->prepare("SELECT * FROM kngil.sp_use_history(?, ?, ?)");
$stmt->execute([
$p_member_id,
$p_user_nm,
$p_dept_nm
]);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
// 3. W2UI를 위해 각 행에 'recid' 필드 주입
$records = [];
foreach ($rows as $index => $row) {
// user_id와 sq_no 조합으로 유일키 생성 (권장)
// 만약 데이터가 없을 경우를 대비해 $index를 활용할 수도 있음
$row['recid'] = ($row['user_id'] ?? 'unknown') . '_' . ($row['sq_no'] ?? $index);
$records[] = $row;
}
// 4. 결과 출력
echo json_encode($records, JSON_UNESCAPED_UNICODE); // 한글 깨짐 방지
} catch (PDOException $e) {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
}
?>