downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

oci_new_cursor> <oci_new_collection
[edit] Last updated: Sat, 07 Jan 2012

view this page in

oci_new_connect

(PHP 5, PECL OCI8 >= 1.1.0)

oci_new_connectConnect to the Oracle server using a unique connection

설명

resource oci_new_connect ( string $username , string $password [, string $connection_string [, string $character_set [, int $session_mode ]]] )

Establishes a new connection to an Oracle server and logs on.

Unlike oci_connect() and oci_pconnect(), oci_new_connect() does not cache connections and will always return a brand-new freshly opened connection handle. This is useful if your application needs transactional isolation between two sets of queries.

인수

username

The Oracle user name.

password

The password for username.

connection_string

접속을 위해 오라클 인스턴스를 포함합니다. » Easy Connect string이나 tnsnames.ora 파일의 Connect Name, 로컬 오라클 인스턴스의 이름일 수 있습니다.

지정하지 않으면, PHP는 접속할 오라클 인스턴스를 찾기 위해 TWO_TASK(리눅스)나 LOCAL(윈도우), 그리고 ORACLE_SID 등의 환경 변수를 사용합니다.

Easy Connect naming 방식을 사용하려면, PHP가 오라클 10g 이상의 클라이언트 라이브러리를 사용해야 합니다. 오라클 10g에서 Easy Connect string 형식은: [//]host_name[:port][/service_name] 입니다. 오라클 11g에서는: [//]host_name[:port][/service_name][:server_type][/instance_name] 입니다. 서비스 이름은 데이터베이스 서버에서 오라클 유틸리티 lsnrctl status를 실행하여 찾을 수 있습니다.

tnsnames.ora 파일은 오라클 넷 검색 경로에 있을 수 있습니다. $ORACLE_HOME/network/admin/etc 등을 포함합니다. TNS_ADMIN을 설정하여 $TNS_ADMIN/tnsnames.ora를 읽게 할 수도 있습니다. 웹 데몬이 이 파일에 읽기 권한을 가지도록 설정하십시오.

character_set

오라클 서버 버전 9.2 이상을 사용하면, 새로운 연결에 사용할 charset 인수를 지정할 수 있습니다. 오라클 서버 < 9.2를 사용한다면, 이 인수는 무시되고, 대신 NLS_LANG 환경 변수를 사용합니다.

session_mode

This parameter is available since version PHP 5 (PECL OCI8 1.1) and accepts the following values: OCI_DEFAULT, OCI_SYSOPER and OCI_SYSDBA. If either OCI_SYSOPER or OCI_SYSDBA were specified, this function will try to establish privileged connection using external credentials. Privileged connections are disabled by default. To enable them you need to set oci8.privileged_connect to On.

PHP 5.3 (PECL OCI8 1.3.4) introduced the OCI_CRED_EXT mode value. This tells Oracle to use External or OS authentication, which must be configured in the database. The OCI_CRED_EXT flag can only be used with username of "/" and a empty password. oci8.privileged_connect may be On or Off.

OCI_CRED_EXT may be combined with the OCI_SYSOPER or OCI_SYSDBA modes.

OCI_CRED_EXT is not supported on Windows for security reasons.

반환값

Returns a connection identifier or FALSE on error.

예제

The following demonstrates how you can separate connections.

Example #1 oci_new_connect() example

<?php
echo "<html><pre>";
$db "";

$c1 oci_connect("scott""tiger"$db);
$c2 oci_new_connect("scott""tiger"$db);

function 
create_table($conn)
{
  
$stmt oci_parse($conn"create table scott.hallo (test
varchar2(64))"
);
  
oci_execute($stmt);
  echo 
$conn " created table\n\n";
}

function 
drop_table($conn)
{
  
$stmt oci_parse($conn"drop table scott.hallo");
  
oci_execute($stmt);
  echo 
$conn " dropped table\n\n";
}

function 
insert_data($conn)
{
  
$stmt oci_parse($conn"insert into scott.hallo
            values('
$conn' || ' ' || to_char(sysdate,'DD-MON-YY HH24:MI:SS'))");
  
oci_execute($stmtOCI_DEFAULT);
  echo 
$conn " inserted hallo\n\n";
}

function 
delete_data($conn)
{
  
$stmt oci_parse($conn"delete from scott.hallo");
  
oci_execute($stmtOCI_DEFAULT);
  echo 
$conn " deleted hallo\n\n";
}

function 
commit($conn)
{
  
oci_commit($conn);
  echo 
$conn " committed\n\n";
}

function 
rollback($conn)
{
  
oci_rollback($conn);
  echo 
$conn " rollback\n\n";
}

function 
select_data($conn)
{
  
$stmt oci_parse($conn"select * from scott.hallo");
  
oci_execute($stmtOCI_DEFAULT);
  echo 
$conn "----selecting\n\n";
  while (
oci_fetch($stmt)) {
    echo 
$conn " <" oci_result($stmt"TEST") . ">\n\n";
  }
  echo 
$conn "----done\n\n";
}

create_table($c1);
insert_data($c1);

select_data($c1);
select_data($c2);

rollback($c1);

select_data($c1);
select_data($c2);

insert_data($c2);
commit($c2);

select_data($c1);

delete_data($c1);
select_data($c1);
select_data($c2);
commit($c1);

select_data($c1);
select_data($c2);

drop_table($c1);
echo 
"</pre></html>";
?>

주의

Note:

In PHP versions before 5.0.0 you must use ocinlogon() instead. The old function name can still be used in current versions, however it is deprecated and not recommended.

참고



add a note add a note User Contributed Notes oci_new_connect
There are no user contributed notes for this page.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites