prepare("SELECT * FROM kngil.sp_item_r()"); $stmt->execute(); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); // 3. W2UI를 위해 각 행에 'recid' 필드 강제 주입 $records = []; foreach ($rows as $row) { $row['recid'] = $row['itm_cd']; // 상품코드를 고유 키로 지정 $records[] = $row; } // 4. 순수 JSON만 출력 (다른 echo나 공백이 섞이면 에러 발생) echo json_encode($records); } catch (PDOException $e) { // 에러 발생 시 그리드가 이해할 수 있게 JSON으로 출력 echo json_encode(['status' => 'error', 'message' => $e->getMessage()]); } ?>