oci_new_connect

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

oci_new_connect锟斤拷锟斤拷一锟斤拷锟斤拷 Oracle 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷

说锟斤拷

oci_new_connect ( string $username , string $password [, string $db [, string $charset [, int $session_mode ]]] ) : resource

oci_new_connect() 锟斤拷锟斤拷一锟斤拷锟斤拷 Oracle 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟接诧拷锟斤拷录锟斤拷锟斤拷 oci_connect() 锟斤拷 oci_pconnect() 锟斤拷同锟斤拷oci_new_connect() 锟斤拷锟结缓锟斤拷锟斤拷锟接o拷锟斤拷锟角会返锟斤拷一锟斤拷全锟铰的刚打开碉拷锟斤拷锟接撅拷锟斤拷锟斤拷锟斤拷锟接︼拷贸锟斤拷锟斤拷锟揭拷锟斤拷锟斤拷锟斤拷询之锟斤拷实锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟矫★拷

锟斤拷选锟侥碉拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟角憋拷锟斤拷 Oracle 实锟斤拷锟斤拷锟斤拷锟街伙拷锟斤拷锟斤拷锟斤拷 tnsnames.ora 锟斤拷锟斤拷目锟叫碉拷锟斤拷锟街★拷锟斤拷锟矫伙拷锟街革拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟� PHP 使锟矫伙拷锟斤拷锟斤拷锟斤拷 ORACLE_SID 锟斤拷 TWO_TASK 锟斤拷锟街憋拷确锟斤拷锟斤拷锟斤拷 Oracle 实锟斤拷锟斤拷锟斤拷锟街猴拷 tnsnames.ora 锟斤拷位锟矫★拷

session_mode 锟斤拷锟斤拷锟皆版本 1.1 锟斤拷锟斤拷貌锟斤拷锟斤拷锟斤拷锟斤拷锟街碉拷锟�OCI_DEFAULT锟斤拷OCI_SYSOPER 锟斤拷 OCI_SYSDBA锟斤拷锟斤拷锟街革拷锟斤拷锟� OCI_SYSOPER 锟斤拷 OCI_SYSDBA 锟斤拷锟斤拷之一锟斤拷oci_new_connect() 锟斤拷锟斤拷锟斤拷使锟斤拷锟解部锟斤拷证锟斤拷息锟斤拷锟斤拷锟斤拷权锟斤拷锟接★拷锟斤拷权锟斤拷锟斤拷默锟较憋拷锟斤拷止锟斤拷要锟斤拷锟矫o拷锟斤拷要锟斤拷 oci8.privileged_connect 锟斤拷为 On锟斤拷

使锟斤拷 Oracle 锟酵伙拷锟剿匡拷锟斤拷确锟斤拷锟街凤拷锟斤拷锟斤拷锟街凤拷锟斤拷锟斤拷锟斤拷要锟斤拷锟斤拷锟捷匡拷锟斤拷址锟斤拷锟斤拷锟狡ワ拷洹o拷锟斤拷锟斤拷匹锟戒,Oracle 锟结尽锟斤拷锟杰地斤拷锟斤拷锟捷达拷锟斤拷锟捷匡拷锟街凤拷锟斤拷锟斤拷锟斤拷转锟斤拷锟斤拷锟斤拷为锟斤拷锟斤拷锟斤拷锟街凤拷锟斤拷锟斤拷锟斤拷锟杰诧拷锟杰革拷锟斤拷锟斤拷锟矫的斤拷锟斤拷锟阶拷锟揭诧拷锟斤拷锟揭恍┦憋拷淇拷锟斤拷锟�

锟斤拷锟斤拷锟街革拷锟斤拷锟絆racle 锟酵伙拷锟斤拷锟斤拷 NLS_LANG 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟街凤拷锟斤拷锟斤拷

锟斤拷锟捷此诧拷锟斤拷锟缴硷拷锟斤拷锟斤拷锟斤拷时锟戒。

锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷示锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟接★拷

Example #1 oci_new_connect() 锟斤拷锟斤拷

<?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>";
?>

oci_new_connect() 锟节筹拷锟斤拷时锟斤拷锟斤拷 FALSE锟斤拷

Note:

锟斤拷 PHP 5.0.0 之前锟侥版本锟斤拷锟斤拷使锟斤拷 ocinlogon() 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷煤锟斤拷锟斤拷锟斤拷锟饺伙拷锟斤拷茫锟轿拷锟斤拷录锟斤拷锟斤拷锟轿� oci_new_connect() 锟侥憋拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟窖憋拷锟斤拷锟斤拷锟斤拷锟斤拷锟狡硷拷使锟矫★拷

锟轿硷拷 oci_connect() 锟斤拷 oci_pconnect()锟斤拷

锟斤拷锟斤拷

username

The Oracle user name.

password

The password for username.

connection_string

锟斤拷锟斤拷要锟斤拷锟接碉拷 Oracle 实锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 » Easy Connect 锟斤拷锟斤拷锟斤拷锟斤拷 tnsnames.ora 锟侥硷拷锟叫碉拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟角憋拷锟斤拷 Oracle 实锟斤拷锟斤拷锟斤拷

锟斤拷锟斤拷锟街革拷锟斤拷锟絇HP 使锟矫伙拷锟斤拷锟斤拷锟斤拷锟斤拷确锟斤拷锟斤拷锟接碉拷 Oracle 实锟斤拷锟斤拷锟斤拷锟斤拷 TWO_TASK锟斤拷Linux 锟铰o拷锟斤拷 LOCAL锟斤拷Windows 锟铰o拷锟斤拷 ORACLE_SID 锟饺★拷

要使锟斤拷 Easy Connect 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷PHP 锟斤拷锟斤拷锟斤拷 Oracle 10g 锟斤拷锟斤拷甙姹撅拷目突锟斤拷丝锟斤拷锟斤拷锟斤拷锟接★拷Oracle 10g 锟斤拷 Easy Connect 锟斤拷锟斤拷式锟斤拷[//]host_name[:port][/service_name]锟斤拷Oracle 11g 锟斤拷为锟斤拷[//]host_name[:port][/service_name][:server_type][/instance_name]锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟捷匡拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟� Oracle 实锟矫筹拷锟斤拷 lsnrctl status 锟揭碉拷锟斤拷

tnsnames.ora 锟侥硷拷锟斤拷锟斤拷 Oracle Net 锟斤拷锟斤拷路锟斤拷锟叫o拷锟斤拷路锟斤拷锟斤拷锟斤拷 $ORACLE_HOME/network/admin 锟斤拷 /etc锟斤拷 锟斤拷一锟街凤拷锟斤拷锟斤拷锟斤拷锟斤拷 TNS_ADMIN 锟皆憋拷通锟斤拷 $TNS_ADMIN/tnsnames.ora 锟斤拷锟斤拷取锟斤拷锟斤拷确锟斤拷 web 锟截伙拷锟斤拷锟教可讹拷取锟斤拷锟侥硷拷锟斤拷

character_set

使锟斤拷 Oracle 锟酵伙拷锟剿匡拷锟斤拷确锟斤拷锟街凤拷锟斤拷锟斤拷锟街凤拷锟斤拷锟斤拷锟斤拷要锟斤拷锟斤拷锟捷匡拷锟斤拷址锟斤拷锟斤拷锟狡ワ拷洹o拷锟斤拷锟斤拷匹锟戒,Oracle 锟结尽锟斤拷锟杰地斤拷锟斤拷锟捷达拷锟斤拷锟捷匡拷锟街凤拷锟斤拷锟斤拷锟斤拷转锟斤拷锟斤拷锟斤拷为锟斤拷锟斤拷锟斤拷锟街凤拷锟斤拷锟斤拷锟斤拷锟杰诧拷锟杰革拷锟斤拷锟斤拷锟矫的斤拷锟斤拷锟阶拷锟揭诧拷锟斤拷锟揭恍┦憋拷淇拷锟斤拷锟�

锟斤拷锟斤拷锟街革拷锟斤拷锟絆racle 锟酵伙拷锟斤拷锟斤拷 NLS_LANG 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟街凤拷锟斤拷锟斤拷

锟斤拷锟捷此诧拷锟斤拷锟缴硷拷锟斤拷锟斤拷锟斤拷时锟戒。

session_mode

锟剿诧拷锟斤拷锟斤拷 PHP 5锟斤拷PECL OCI8 1.1锟斤拷锟芥本锟斤拷始锟斤拷锟矫o拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷值锟斤拷OCI_DEFAULT锟斤拷OCI_SYSOPER 锟斤拷 OCI_SYSDBA锟斤拷锟斤拷为 OCI_SYSOPER 锟斤拷 OCI_SYSDBA 锟斤拷锟斤拷之一锟斤拷锟剿猴拷锟斤拷锟斤拷锟斤拷使锟斤拷锟解部锟斤拷证锟介建锟斤拷锟斤拷锟斤拷权锟斤拷锟斤拷锟接★拷锟斤拷锟斤拷权锟斤拷锟斤拷锟斤拷默锟斤拷锟角斤拷锟矫的★拷锟斤拷要锟斤拷 oci8.privileged_connect 锟斤拷为 On 锟斤拷锟斤拷锟矫★拷

PHP 5.3锟斤拷PECL OCI8 1.3.4锟斤拷锟斤拷锟斤拷锟斤拷 OCI_CRED_EXT 模式值锟斤拷使锟斤拷锟解部锟斤拷锟斤拷锟较低筹拷锟街わ拷锟斤拷锟斤拷锟� Oracle 锟斤拷锟捷匡拷锟叫斤拷锟斤拷锟斤拷锟矫★拷OCI_CRED_EXT 锟斤拷志只锟斤拷锟斤拷锟斤拷锟矫伙拷为 "/"锟斤拷锟斤拷锟斤拷为锟秸碉拷锟斤拷锟斤拷锟�oci8.privileged_connect 锟斤拷为 On 锟斤拷 Off锟斤拷

OCI_CRED_EXT 锟斤拷锟斤拷 OCI_SYSOPER 锟斤拷 OCI_SYSDBA 模式锟斤拷锟绞癸拷谩锟�

OCI_CRED_EXT 锟斤拷锟节帮拷全锟斤拷原锟斤拷支锟斤拷 Windows 系统锟斤拷

锟斤拷锟斤拷值

Returns a connection identifier or FALSE on error.

锟斤拷锟斤拷

The following demonstrates how you can separate connections.

Example #2 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. 锟节碉拷前锟芥本锟叫o拷锟缴的猴拷锟斤拷锟斤拷锟斤拷锟斤拷锟皆憋拷使锟矫o拷锟斤拷锟窖撅拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷使锟矫★拷

锟轿硷拷

  • oci_connect() - 锟斤拷锟斤拷一锟斤拷锟斤拷 Oracle 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
  • oci_pconnect() - 使锟斤拷一锟斤拷锟街撅拷锟斤拷锟斤拷锟斤拷锟斤拷 Oracle 锟斤拷锟捷匡拷