mysqli_stmt::$error

(PHP 5, PHP 7, PHP 8)

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


설명

객체 지향 스타일

string $mysqli_stmt->error;

절차적 스타일

mysqli_stmt_error(mysqli_stmt $statement): string

성공하거나 실패할 수 있는 가장 최근에 호출된 명령문 함수에 대한 오류 메시지가 포함된 문자열을 반환합니다.


매개변수

statement
절차적 스타일 전용: mysqli_stmt_init()에 의해 반환된 mysqli_stmt 객체.

반환 값

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


Examples

예제 #1 객체 지향 스타일

객체 지향 스타일

                  
<?php
/* Open a connection */
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

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

$mysqli->query("CREATE TABLE myCountry LIKE Country");
$mysqli->query("INSERT INTO myCountry SELECT * FROM Country");


$query = "SELECT Name, Code FROM myCountry ORDER BY Name";
if ($stmt = $mysqli->prepare($query)) {

    /* drop table */
    $mysqli->query("DROP TABLE myCountry");

    /* execute query */
    $stmt->execute();

    printf("Error: %s.\n", $stmt->error);

    /* close statement */
    $stmt->close();
}

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

예제 #2 절차적 스타일

                  
<?php
/* Open a connection */
$link = mysqli_connect("localhost", "my_user", "my_password", "world");

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

mysqli_query($link, "CREATE TABLE myCountry LIKE Country");
mysqli_query($link, "INSERT INTO myCountry SELECT * FROM Country");


$query = "SELECT Name, Code FROM myCountry ORDER BY Name";
if ($stmt = mysqli_prepare($link, $query)) {

    /* drop table */
    mysqli_query($link, "DROP TABLE myCountry");

    /* execute query */
    mysqli_stmt_execute($stmt);

    printf("Error: %s.\n", mysqli_stmt_error($stmt));

    /* close statement */
    mysqli_stmt_close($stmt);
}

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

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

Error: Table 'world.myCountry' doesn't exist.
                

기타