라이브러리
[PHP] mysqli_warning::next - 다음 경고 가져오기
PHP에서 mysqli_warning::next
PHP의 mysqli 확장에서 `mysqli_warning` 클래스는 MySQL 서버에서 발생한 경고 메시지를 나타냅니다. `mysqli_warning::next` 메서드는 다음 경고 메시지를 반환합니다.
# 사용법
`mysqli_warning::next` 메서드는 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
php
$mysqli = new mysqli("호스트", "이름", "비밀번호", "데이터베이스");
// 쿼리 실행
$result = $mysqli->query("SELECT * FROM 테이블 WHERE 조건");
// 경고 메시지 얻기
$warning = $mysqli->warnings();
// 다음 경고 메시지 얻기
$next_warning = $mysqli->nextWarning();
// 경고 메시지 내용 출력
echo $next_warning->getMessage();
# 예제
다음 예제는 `mysqli_warning::next` 메서드를 사용하여 MySQL 서버에서 발생한 경고 메시지를 얻는 방법을 보여줍니다.
#hostingforum.kr
php
<?php
$mysqli = new mysqli("localhost", "root", "", "test");
// 테이블 생성
$mysqli->query("CREATE TABLE test (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255)
)");
// 테이블에 데이터 삽입
$mysqli->query("INSERT INTO test (name) VALUES ('John')");
// 테이블에 데이터 삽입 (경고 발생)
$mysqli->query("INSERT INTO test (name) VALUES ('John')");
// 경고 메시지 얻기
$warning = $mysqli->nextWarning();
// 경고 메시지 내용 출력
echo $warning->getMessage(); // "Duplicate entry 'John' for key 'PRIMARY'"
// 테이블 삭제
$mysqli->query("DROP TABLE test");
// 테이블 생성 (이미 존재하는 테이블 이름)
$mysqli->query("CREATE TABLE test (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255)
)");
// 경고 메시지 얻기
$warning = $mysqli->nextWarning();
// 경고 메시지 내용 출력
echo $warning->getMessage(); // "Table 'test' already exists"
?>
# 참고
* `mysqli_warning` 클래스의 메서드 목록: [https://www.php.net/manual/en/class.mysqli-warning.php](https://www.php.net/manual/en/class.mysqli-warning.php)
* `mysqli_warning` 클래스의 속성 목록: [https://www.php.net/manual/en/class.mysqli-warning.php](https://www.php.net/manual/en/class.mysqli-warning.php)
* MySQL 서버에서 발생한 경고 메시지에 대한 자세한 내용: [https://dev.mysql.com/doc/refman/8.0/en/warning.html](https://dev.mysql.com/doc/refman/8.0/en/warning.html)
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.