api 가 오류 나네요
본문
혹시 api의 코드가 문제가 잇을까요? 지금은 테스트를 하는 중입니다
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
// 1. 보안 설정 및 JSON 형식 지정
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
// 2. 그누보드의 config.php 파일을 불러옵니다.
// api_posts.php 파일이 config.php 파일보다 한 단계 아래 폴더에 있을 경우 '../' 사용
require_once('./config.php');
// 3. MySQL 데이터베이스에 접속
$conn = mysqli_connect(G5_MYSQL_HOST, G5_MYSQL_USER, G5_MYSQL_PASSWORD, G5_MYSQL_DB);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// 4. SQL 쿼리 실행: '공지사항' 게시판(g5_write_notice)의 최신 글 5개 가져오기
// !!! 중요 !!! g5_write_notice 부분을 사용하려는 게시판 테이블 이름으로 변경해야 합니다.
// (예: 자유게시판이면 g5_write_free 등으로)
$sql = "SELECT wr_id, wr_subject, wr_name, wr_datetime FROM g5_write_notice ORDER BY wr_num, wr_reply LIMIT 5";
$result = mysqli_query($conn, $sql);
$posts = array(); // 게시글 목록을 담을 빈 상자(배열) 준비
if ($result && mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
// DB에서 한 줄씩 데이터를 가져와 $posts 상자에 추가합니다.
$posts[] = $row;
}
$status = "success";
} else {
$status = "error";
}
// 5. DB 접속 종료
mysqli_close($conn);
// 6. 데이터를 JSON 형식으로 가공하고 출력합니다.
$response = array(
"status" => $status,
"data" => $posts // 이제 'data' 안에 게시글 목록 전체가 들어갑니다.
);
echo json_encode($response, JSON_UNESCAPED_UNICODE);
?>
고수님들 혹시 어디서 오류가 나는지좀 잡아봐 주세요
답변 3
require_once('./config.php');
이 코드를
require_once('./common.php');
이렇게만 바꿔주세요
잘 나옵니다.
![]()
ini_set('display_errors', 1);
error_reporting(E_ALL);
상단에 디버깅 있는데 혹시 에러 내용은 따로 안보이실까요?
상단 에러 내용인데요 . 아직 모르는 부분이 많아서 계속 몇일 확인을 해야 할거 같아요 .
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at *** 개인정보보호를 위한 이메일주소 노출방지 *** to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.