라이브러리

[PHP] mysqli::get_warnings - SHOW WARNINGS의 결과 가져오기




PHP에서 mysqli::get_warnings 사용하기


PHP에서 mysqli 확장을 사용하여 데이터베이스와 상호 작용할 때, 에러나 경고를 처리하는 방법이 있습니다. mysqli::get_warnings 메서드는 이러한 에러나 경고를 처리하는 데 도움이 됩니다.

# mysqli::get_warnings 메서드


mysqli::get_warnings 메서드는 현재 연결된 데이터베이스의 경고를 반환합니다. 이 메서드는 mysqli::get_warnings_mode() 메서드를 사용하여 활성화하거나 비활성화할 수 있습니다.

# 예제


#hostingforum.kr
php

<?php

// 데이터베이스 연결

$conn = mysqli_connect('localhost', 'root', 'password', 'mydb');



// 에러와 경고를 활성화합니다.

mysqli_report(MYSQLI_REPORT_ALL);



// 쿼리 실행

$result = mysqli_query($conn, "SELECT * FROM non_existent_table");



// 경고를 가져옵니다.

$warnings = mysqli_get_warnings($conn);



// 경고를 출력합니다.

while ($warning = mysqli_next_warning($conn)) {

    echo $warning->message . "
";

}



// 데이터베이스 연결을 닫습니다.

mysqli_close($conn);

?>



# mysqli::get_warnings_mode() 메서드


mysqli::get_warnings_mode() 메서드는 현재 연결된 데이터베이스의 경고 모드(활성화/비활성화)를 반환하거나 설정합니다.

# 예제


#hostingforum.kr
php

<?php

// 데이터베이스 연결

$conn = mysqli_connect('localhost', 'root', 'password', 'mydb');



// 경고 모드를 활성화합니다.

mysqli_report(MYSQLI_REPORT_ALL);



// 경고 모드를 가져옵니다.

$mode = mysqli_get_warnings_mode($conn);

echo "현재 경고 모드: $mode
";



// 경고 모드를 비활성화합니다.

mysqli_report(MYSQLI_REPORT_OFF);



// 경고 모드를 가져옵니다.

$mode = mysqli_get_warnings_mode($conn);

echo "현재 경고 모드: $mode
";



// 데이터베이스 연결을 닫습니다.

mysqli_close($conn);

?>



# mysqli::next_warning() 메서드


mysqli::next_warning() 메서드는 현재 연결된 데이터베이스의 다음 경고를 반환합니다.

# 예제


#hostingforum.kr
php

<?php

// 데이터베이스 연결

$conn = mysqli_connect('localhost', 'root', 'password', 'mydb');



// 에러와 경고를 활성화합니다.

mysqli_report(MYSQLI_REPORT_ALL);



// 쿼리 실행

$result = mysqli_query($conn, "SELECT * FROM non_existent_table");



// 경고를 가져옵니다.

$warning = mysqli_next_warning($conn);



// 경고를 출력합니다.

while ($warning) {

    echo $warning->message . "
";

    $warning = mysqli_next_warning($conn);

}



// 데이터베이스 연결을 닫습니다.

mysqli_close($conn);

?>



# mysqli::get_warnings() 메서드


mysqli::get_warnings() 메서드는 현재 연결된 데이터베이스의 경고를 반환합니다.

# 예제


#hostingforum.kr
php

<?php

// 데이터베이스 연결

$conn = mysqli_connect('localhost', 'root', 'password', 'mydb');



// 에러와 경고를 활성화합니다.

mysqli_report(MYSQLI_REPORT_ALL);



// 쿼리 실행

$result = mysqli_query($conn, "SELECT * FROM non_existent_table");



// 경고를 가져옵니다.

$warnings = mysqli_get_warnings($conn);



// 경고를 출력합니다.

while ($warning = mysqli_next_warning($conn)) {

    echo $warning->message . "
";

}



// 데이터베이스 연결을 닫습니다.

mysqli_close($conn);

?>



이 예제에서는 mysqli::get_warnings() 메서드를 사용하여 현재 연결된 데이터베이스의 경고를 가져옵니다. 경고를 가져온 후, mysqli::next_warning() 메서드를 사용하여 경고를 하나씩 출력합니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 381 페이지

검색

게시물 검색