mysqli::$error

(PHP 5, PHP 7, PHP 8)

mysqli::$error -- mysqli_error — 마지막 오류에 대한 문자열 설명을 반환합니다.


설명

객체 지향 스타일

string $mysqli->error;

절차적 스타일

mysqli_error(mysqli $mysql): string

성공하거나 실패할 수 있는 가장 최근의 MySQLi 함수 호출에 대한 마지막 오류 메시지를 반환합니다.


매개변수

mysql
절차적 스타일 전용: mysqli_connect() 또는 mysqli_init()에 의해 반환된 mysqli 객체

반환 값

오류를 설명하는 문자열입니다. 오류가 발생하지 않은 경우 빈 문자열입니다.


Examples

예제 #1 $mysqli->error 예제

객체 지향 스타일

                  
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

/* check connection */
if ($mysqli->connect_errno) {
    printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}

if (!$mysqli->query("SET a=1")) {
    printf("Error message: %s\n", $mysqli->error);
}

/* close connection */
$mysqli->close();
?>
                  
                

절차적 스타일

                  
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

if (!mysqli_query($link, "SET a=1")) {
    printf("Error message: %s\n", mysqli_error($link));
}

/* close connection */
mysqli_close($link);
?>
                  
                

위의 예는 다음을 출력합니다.

Error message: Unknown system variable 'a'
                

기타