라이브러리
[PHP] pg_result_error - 결과와 관련된 오류 메시지 가져오기
pg_result_error 함수란?
`pg_result_error` 함수는 PostgreSQL 데이터베이스와 연결된 PHP 확장에 의해 제공되는 함수입니다. 이 함수는 현재 실행 중인 쿼리의 오류 메시지를 반환합니다.
사용법
`pg_result_error` 함수는 두 개의 매개 변수를 받습니다. 첫 번째 매개 변수는 `result` 변수로, 현재 실행 중인 쿼리의 결과를 나타내는 객체입니다. 두 번째 매개 변수는 `detail` 변수로, 오류 메시지의 세부 정보를 반환하는 옵션입니다.
예제
#hostingforum.kr
php
<?php
// PostgreSQL 데이터베이스와 연결
$conn = pg_connect("host=localhost dbname=mydb user=myuser password=mypassword");
// 쿼리 실행
$result = pg_query($conn, "SELECT * FROM non_existent_table");
// 오류 메시지 출력
$error = pg_result_error($result);
echo "오류 메시지: $error
";
// 세부 정보 출력
$detail = pg_result_error_field($result, PGSQL_DIAG_SQLERRM);
echo "세부 정보: $detail
";
// PostgreSQL 데이터베이스 연결 해제
pg_close($conn);
?>
결과
#hostingforum.kr
오류 메시지: ERROR: relation "non_existent_table" does not exist
세부 정보: ERROR: relation "non_existent_table" does not exist
참고
* `pg_result_error` 함수는 현재 실행 중인 쿼리의 오류 메시지를 반환합니다.
* `pg_result_error_field` 함수는 오류 메시지의 세부 정보를 반환하는 옵션입니다.
* `PGSQL_DIAG_SQLERRM`는 오류 메시지의 세부 정보를 반환하는 상수입니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.