LXXIV. 오라클 8 함수

이 함수들을 통해 오라클 8과 오라클 7 데이터베이스를 연동하여 사용한다. Oracle8 Call-Interface (OCI8)를 사용하며, 이 함수들을 사용하려면 오라클8 클라이언트 라이브러리(Oracle8 client libraries)가 필요하다.

이 함수는 표준 오라클 함수보다 유연하다. PHP의 전역 변수와 지역 변수들의 오라클 위치보유자(Oracle placeholder) 로의 연계(binding), full LOB, FILE, ROWID를 지원하며, user-supplied define variable을 사용할 수 있도록 해 준다.

이 함수를 사용하기 전에 오라클 계정과 웹 데몬 계정에 유효한 오라클 환경변수를 적용했는지 확인해야한다. 적용시킬 환경변수:

  • ORACLE_HOME

  • ORACLE_SID

  • LD_PRELOAD

  • LD_LIBRARY_PATH

  • NLS_LANG

  • ORA_NLS33

웹서버 계정으로 위 환경변수를 적용한후에, 웹서버 계정(nobody, www)을 오라클 그룹에 추가했는지 확인해야 한다.

웹서버가 시작하지 않거나 시작시 제대로 작동하지 않으면: 아파치가 pthread 라이브러리에 링크되어있는지 체크하라:

# ldd /www/apache/bin/httpd 
    libpthread.so.0 => /lib/libpthread.so.0 (0x4001c000)
    libm.so.6 => /lib/libm.so.6 (0x4002f000)
    libcrypt.so.1 => /lib/libcrypt.so.1 (0x4004c000)
    libdl.so.2 => /lib/libdl.so.2 (0x4007a000)
    libc.so.6 => /lib/libc.so.6 (0x4007e000)
    /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

libpthread가 보이지 않으면 아파치를 다시 설치해야한다 :

# cd /usr/src/apache_1.3.xx
# make clean
# LIBS=-lpthread ./config.status
# make
# make install

예 1. OCI Hints

<?php
// by sergo@bacup.ru

// Use option: OCI_DEFAULT for execute command to delay execution
OCIExecute($stmt, OCI_DEFAULT);

// for retrieve data use (after fetch):

$result = OCIResult($stmt, $n);
if (
is_object ($result)) $result = $result->load();

// For INSERT or UPDATE statement use:

$sql = "insert into table (field1, field2) values (field1 = 'value',
field2 = empty_clob()) returning field2 into :field2"
;
OCIParse($conn, $sql);
$clob = OCINewDescriptor($conn, OCI_D_LOB);
OCIBindByName ($stmt, ":field2", &amp;$clob, -1, OCI_B_CLOB);
OCIExecute($stmt, OCI_DEFAULT);
$clob->save ("some text");
OCICommit($conn);

?&
gt;

커맨드 라인(command-line)에서의 사용 방식과 동일하게 내장 프로시저(stored procedures)를 사용할 수 있다.

예 2. 내장 프로시저(Stored Procedures) 사용하기

<?php
// by webmaster@remoterealty.com
$sth = OCIParse ( $dbh, "begin sp_newaddress( :address_id, '$firstname',
'$lastname', '$company', '$address1', '$address2', '$city', '$state',
'$postalcode', '$country', :error_code );end;"
);

// This calls stored procedure sp_newaddress, with :address_id being an
// in/out variable and :error_code being an out variable.
// Then you do the binding:

   
OCIBindByName ( $sth, ":address_id", $addr_id, 10 );
   
OCIBindByName ( $sth, ":error_code", $errorcode, 10 );
   
OCIExecute ( $sth );

?>

차례
oci_bind_by_name --  Binds the PHP variable to the Oracle placeholder
oci_cancel -- Cancels reading from cursor
oci_close -- Closes Oracle connection
collection->append -- Appends an object to the collection
collection->assign -- Assigns a value to the collection from another existing collection
collection->assignElem -- Assigns a value to the element of the collection
collection->getElem -- Returns value of the element
collection->max -- Gets the maximum number of elements in the collection
collection->size -- Returns size of the collection
collection->trim -- Trims elements from the end of the collection
oci_commit -- Commits outstanding statements
oci_connect -- Establishes a connection to Oracle server
oci_define_by_name --  Uses a PHP variable for the define-step during a SELECT
oci_error -- Returns the last error found
oci_execute -- Executes a statement
oci_fetch_all -- Fetches all rows of result data into an array
oci_fetch_array -- Returns the next row from the result data as an associative or numeric array, or both
oci_fetch_assoc -- Returns the next row from the result data as an associative array
oci_fetch_object -- Returns the next row from the result data as an object
oci_fetch_row -- Returns the next row from the result data as a numeric array
oci_fetch -- Fetches the next row into result-buffer
oci_field_is_null -- Checks if the field is NULL
oci_field_name -- Returns the name of a field from the statement
oci_field_precision -- Tell the precision of a field
oci_field_scale -- Tell the scale of the field
oci_field_size -- Returns field's size
oci_field_type_raw -- Tell the raw Oracle data type of the field
oci_field_type -- Returns field's data type
collection->free -- Frees resources associated with collection object
descriptor->free -- Frees resources associated with descriptor
oci_free_statement --  Frees all resources associated with statement or cursor
oci_internal_debug -- Enables or disables internal debug output
lob->append -- Appends data from the large object to another large object
lob->close -- Closes LOB descriptor
oci_lob_copy -- Copies large object
lob->eof -- Tests for end-of-file on a large object's descriptor
lob->erase -- Erases a specified portion of the internal LOB data
lob->export -- Exports LOB's contents to a file
lob->flush -- Flushes/writes buffer of the LOB to the server
lob->import -- Imports file data to the LOB
oci_lob_is_equal -- Compares two LOB/FILE locators for equality
lob->load -- Returns large object's contents
lob->read -- Reads part of large object
lob->rewind -- Moves the internal pointer to the beginning of the large object
lob->save -- Saves data to the large object
lob->seek -- Sets the internal pointer of the large object
lob->size -- Returns size of large object
lob->tell -- Returns current position of internal pointer of large object
lob->truncate -- Truncates large object
lob->writeTemporary -- Writes temporary large object
lob->write -- Writes data to the large object
oci_new_collection -- Allocates new collection object
oci_new_connect -- Establishes a new connection to the Oracle server
oci_new_cursor -- Allocates and returns a new cursor (statement handle)
oci_new_descriptor -- Initializes a new empty LOB or FILE descriptor
oci_num_fields --  Returns the number of result columns in a statement
oci_num_rows -- Returns number of rows affected during statement execution
oci_parse -- Prepares Oracle statement for execution
oci_password_change -- Changes password of Oracle's user
oci_pconnect -- Connect to an Oracle database using a persistent connection
oci_result -- Returns field's value from the fetched row
oci_rollback -- Rolls back outstanding transaction
oci_server_version -- Returns server version
oci_set_prefetch -- Sets number of rows to be prefetched
oci_statement_type -- Returns the type of an OCI statement
OCIBindByName --  오라클 위치보유자(Placeholder)를 PHP 변수에 연계(bind)시킨다.
OCICancel -- 커서로부터 읽기를 취소한다
ocicloselob -- Closes lob descriptor
ocicollappend -- Append an object to the collection
ocicollassign -- Assign a collection from another existing collection
ocicollassignelem -- Assign element val to collection at index ndx
ocicollgetelem -- Retrieve the value at collection index ndx
ocicollmax --  Return the max value of a collection. For a varray this is the maximum length of the array
ocicollsize -- Return the size of a collection
ocicolltrim -- Trim num elements from the end of a collection
OCIColumnIsNULL -- 결과 컬럼이 널(NULL)인지 테스트한다
OCIColumnName -- 컬럼의 이름을 리턴한다.
ocicolumnprecision -- Tell the precision of a column
ocicolumnscale -- Tell the scale of a column
OCIColumnSize -- 결과 컬럼 사이즈를 리턴한다
OCIColumnType -- 컬럼의 데이터 타입을 리턴한다.
ocicolumntyperaw -- Tell the raw oracle data type of a column
OCICommit -- 미결정된 트랜잭션을 커밋시킨다.
OCIDefineByName --  한 SELECT 구문사용시 정의단계(define-step)를 위한 PHP 변수를 할당한다.
OCIError -- stmt|conn|global의 제일 마지막 에러를 리턴한다. 아무 에러도 없었다면 FALSE를 리턴한다.
OCIExecute -- SQL 구문(Statement)을 수행한다.
OCIFetch -- 결과 버퍼(result-buffer)로 다음 열을 페치한다
OCIFetchInto -- 결과 배열(result-array)에 다음 열을 페치한다
OCIFetchStatement -- 배열에 모든 열의 결과 값을 페치한다.
ocifreecollection -- Deletes collection object
OCIFreeCursor --  커서(cursor)에 연관된 모든 자원을 해제한다.
OCIFreeDesc -- 큰 객체(large object) descriptor를 삭제한다.
OCIFreeStatement --  구문(statement)에 연관된 모든 자원을 해제한다.
lob->getBuffering -- Returns current state of buffering for large object
OCIInternalDebug --  내부 디버그 출력을 활성화 시키거나, 비활성화 시킨다. 기본값으로 비활성화 되어있다.
ociloadlob -- Loads a large object
OCILogOff -- 오라클로부터 접속을 해제한다.
OCILogon -- 오라클 데이터베이스에 접속한다.
ocinewcollection -- Initialize a new collection
OCINewCursor --  새로운 커서(구문 핸들)를 리턴한다 - ref-cursor를 연계하기위함.
OCINewDescriptor --  LOB/FILE의 비어있는 새로운 descriptor를 초기화한다 (LOB 이 기본값이다)
OCINLogon -- 오라클 데이터베이스에 접속하고 새로운 접속을 이용해서 로그온한다. 새로운 세션(session)을 넘겨준다.
OCINumCols --  구문 결과값의 컬럼의 갯수를 리턴한다
OCIParse -- 질의(query)를 해석하고 구문(statement)를 리턴한다
OCIPLogon -- 오라클 데이터베이스에 접속하고 영속적 DB 접속 (persistant connection) 을 이용해서 로그온한다. 또다른 새로운 세션(session)을 넘겨준다.
OCIResult -- 페치된 열의 컬럼 값을 리턴한다
OCIRollback -- 미결정된 트랜잭션을 롤백한다.
OCIRowCount -- 적용되어진 열의 갯수를 가져온다
ocisavelob -- Saves a large object
ocisavelobfile -- Saves a large object file
ociserverversion -- Return a string containing server version information
lob->setBuffering -- Changes current state of buffering for large object
OCISetPrefetch -- 사용할 열의 갯수를 설정한다
OCIStatementType -- OCI 구문(statement)의 타입을 리턴한다.
ociwritelobtofile -- Saves a large object file
ociwritetemporarylob -- Writes temporary blob