라이브러리
[PHP] oci_fetch - 쿼리에서 다음 행을 내부 버퍼로 가져옵니다.
PHP와 Oracle의 통합: oci_fetch
PHP와 Oracle Database를 통합하는 방법 중 하나는 Oracle의 확장 함수인 `oci`를 사용하는 것입니다. `oci_fetch` 함수는 Oracle Database에서 쿼리 결과를 가져와 PHP 변수에 저장하는 데 사용됩니다.
oci_fetch 함수의 사용법
`oci_fetch` 함수는 다음과 같은 형식으로 사용됩니다.
#hostingforum.kr
php
bool oci_fetch ( resource $statement )
* `$statement` : 쿼리 결과를 가져올 Oracle Statement 객체입니다.
예제: oci_fetch 함수 사용하기
Oracle Database에 연결된 후에 쿼리 결과를 가져와 PHP 변수에 저장하는 예제입니다.
#hostingforum.kr
php
// Oracle Database에 연결
$dsn = 'oci:dbname=ORCL;host=localhost';
$username = '사용자 이름';
$password = '비밀번호';
$conn = oci_connect($username, $password, $dsn);
if (!$conn) {
$e = oci_error();
print "에러 내용: " . $e['message'];
exit;
}
// 쿼리 실행
$query = "SELECT * FROM 테이블명";
$stmt = oci_parse($conn, $query);
oci_execute($stmt);
// 쿼리 결과를 가져와 PHP 변수에 저장
while (oci_fetch($stmt)) {
$row = oci_fetch_array($stmt, OCI_ASSOC + OCI_RETURN_NULLS);
print_r($row);
}
// Oracle Database 연결 종료
oci_close($conn);
oci_fetch_array 함수
`oci_fetch_array` 함수는 쿼리 결과를 가져와 PHP 배열에 저장하는 데 사용됩니다. `$fetchMode` 파라미터를 사용하여 결과를 가져올 수 있습니다.
#hostingforum.kr
php
array oci_fetch_array ( resource $statement [, int $fetchMode ] )
* `$statement` : 쿼리 결과를 가져올 Oracle Statement 객체입니다.
* `$fetchMode` : 결과를 가져올 모드입니다. (OCI_ASSOC, OCI_NUM, OCI_BOTH)
예제: oci_fetch_array 함수 사용하기
Oracle Database에 연결된 후에 쿼리 결과를 가져와 PHP 배열에 저장하는 예제입니다.
#hostingforum.kr
php
// Oracle Database에 연결
$dsn = 'oci:dbname=ORCL;host=localhost';
$username = '사용자 이름';
$password = '비밀번호';
$conn = oci_connect($username, $password, $dsn);
if (!$conn) {
$e = oci_error();
print "에러 내용: " . $e['message'];
exit;
}
// 쿼리 실행
$query = "SELECT * FROM 테이블명";
$stmt = oci_parse($conn, $query);
oci_execute($stmt);
// 쿼리 결과를 가져와 PHP 배열에 저장
while (oci_fetch_array($stmt, OCI_ASSOC + OCI_RETURN_NULLS)) {
$row = oci_fetch_array($stmt, OCI_ASSOC + OCI_RETURN_NULLS);
print_r($row);
}
// Oracle Database 연결 종료
oci_close($conn);
결론
`oci_fetch` 함수와 `oci_fetch_array` 함수는 Oracle Database에서 쿼리 결과를 가져와 PHP 변수에 저장하는 데 사용됩니다. 위 예제를 참고하여 Oracle Database와 PHP를 통합하는 방법을 이해할 수 있습니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.