oci_error

(PHP 5, PHP 7, PHP 8, PECL OCI8 >= 1.1.0)

oci_error — 발견된 마지막 오류를 반환합니다.


설명

oci_error(?resource $connection_or_statement = null): array|false

마지막으로 발견된 오류를 반환합니다.

함수는 오류가 발생한 직후에 호출되어야 합니다. 오류는 성공적인 명령문으로 지워집니다.


매개변수

connection_or_statement
대부분의 오류에서 connection_or_statement는 실패한 함수 호출에 전달된 리소스 핸들입니다. oci_connect() 연결 오류의 경우 oci_new_connect() 또는 oci_pconnect() null이 전달되어야 합니다.

반환 값

오류가 발견되지 않으면 oci_error()false를 반환합니다. 그렇지 않으면 oci_error()는 오류 정보를 연관 배열로 반환합니다.

oci_error() 배열 설명

Array key Type 설명
code int Oracle 오류 번호입니다.
message string Oracle 오류 텍스트입니다.
offset int SQL 문에서 오류의 바이트 위치입니다. 문이 없으면 0입니다.
sqltext string SQL 문 텍스트입니다. 문이 없으면 빈 문자열입니다.

변경 로그

버전 설명
8.0.0, PECL OCI8 3.0.0 connection_or_statement는 이제 null을 허용합니다.

Examples

예제 #1 연결 오류 후 Oracle 오류 메시지 표시

                  
<?php
$conn = oci_connect("hr", "welcome", "localhost/XE");
if (!$conn) {
    $e = oci_error();   // For oci_connect errors do not pass a handle
    trigger_error(htmlentities($e['message']), E_USER_ERROR);
}
?>
                  
                

예제 #2 구문 분석 오류 후 Oracle 오류 메시지 표시

                 
<?php
$stid = oci_parse($conn, "select ' from dual");  // note mismatched quote
if (!$stid) {
    $e = oci_error($conn);  // For oci_parse errors pass the connection handle
    trigger_error(htmlentities($e['message']), E_USER_ERROR);
}
?>
                 
               

예제 #3 Oracle 에러 메시지, 문제가 있는 문장, 실행 에러가 발생한 위치 표시

                
<?php
$stid = oci_parse($conn, "select does_not_exist from dual");
$r = oci_execute($stid);
if (!$r) {
    $e = oci_error($stid);  // For oci_execute errors pass the statement handle
    print htmlentities($e['message']);
    print "\n<pre>\n";
    print htmlentities($e['sqltext']);
    printf("\n%".($e['offset']+1)."s", "^");
    print  "\n</pre>\n";
}
?>