[질답/버그/제안] api 오류
test
분류아미나샘플
조회15
댓글0

api_posts.php 파일 내용 입니다 api경로는 /www/api/api_posts.php 입니다 

아래는 파일내용입니다  api는 처음이라 잘 모르겟습니다,  아래 파일 구성좀 봐 주세요 

파일을직접 불럿을때 이런 에러가 나오네요  = 전체원본파일 추가 합니다 - 현재로선 어떤 증상인지 알수도 없네요

원본의 상태좀 봐주세요 어떤게 잘못된건지 파악좀  해주세요 .

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at postmaster@bannerb11.cafe24.com 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.





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);

?>

0 Comments
포토 제목