PHP Manual
Prev |  | Next

# OCINLogon

OCINLogon -- Connect to an Oracle database and log on using a new connection. Returns a new session.

## Description

`int OCINLogon`(string username, string password, string [db]);

OCINLogon() creates a new connection to an Oracle 8 database and logs on. The optional third parameter can either contain the name of the local Oracle instance or the name of the entry in tnsnames.ora to which you want to connect. If the optional third parameter is not specified, PHP uses the environment variables ORACLE_SID (Oracle instance) or TWO_TASK (tnsnames.ora) to determine which database to connect to.

OCINLogon() forces a new connection. This should be used if you need to isolate a set of transactions. By default, connections are shared at the page level if using OCILogon() or at the web server process level if using OCIPLogon(). If you have multiple connections open using OCINLogon(), all commits and rollbacks apply to the specified connection only.

This example demonstrates how the connections are separated.

Example 1. OCINLogon
      1
      2 <?php
      3 print "<HTML><PRE>";
      4 $db = "";
      5
      6 $c1 = ocilogon("scott","tiger",$db);
      7 $c2 = ocinlogon("scott","tiger",$db);
      8
      9 function create_table($conn)
     10 { $stmt = ociparse($conn,"create table scott.hallo (test
     11 varchar2(64))");
     12   ociexecute($stmt);
     13   echo $conn." created table\n\n";
     14 }
     15
     16 function drop_table($conn)
     17 { $stmt = ociparse($conn,"drop table scott.hallo");
     18   ociexecute($stmt);
     19   echo $conn." dropped table\n\n";
     20 }
     21
     22 function insert_data($conn)
     23 { $stmt = ociparse($conn,"insert into scott.hallo values('$conn' || ' ' || to_char(sysdate,'DD-MON-YY HH24:MI:SS'))");
     24   ociexecute($stmt,OCI_DEFAULT);
     25   echo $conn." inserted hallo\n\n";
     26 }
     27
     28 function delete_data($conn)
     29 { $stmt = ociparse($conn,"delete from scott.hallo");
     30   ociexecute($stmt,OCI_DEFAULT);
     31   echo $conn." deleted hallo\n\n";
     32 }
     33
     34 function commit($conn)
     35 { ocicommit($conn);
     36   echo $conn." commited\n\n";
     37 }
     38
     39 function rollback($conn)
     40 { ocirollback($conn);
     41   echo $conn." rollback\n\n";
     42 }
     43
     44 function select_data($conn)
     45 { $stmt = ociparse($conn,"select * from scott.hallo");
     46   ociexecute($stmt,OCI_DEFAULT);
     47   echo $conn."----selecting\n\n";
     48   while (ocifetch($stmt))
     49     echo $conn." <".ociresult($stmt,"TEST").">\n\n";
     50   echo $conn."----done\n\n";
     51 }
     52
     53 create_table($c1);
     54 insert_data($c1);
     55
     56 select_data($c1);
     57 select_data($c2);
     58
     59 rollback($c1);
     60
     61 select_data($c1);
     62 select_data($c2);
     63
     64 insert_data($c2);
     65 commit($c2);
     66
     67 select_data($c1);
     68
     69 delete_data($c1);
     70 select_data($c1);
     71 select_data($c2);
     72 commit($c1);
     73
     74 select_data($c1);
     75 select_data($c2);
     76
     77
     78 drop_table($c1);
     79 print "</PRE></HTML>";
     80 ?>

See also OCILogon() and OCIPLogon().

Prev | Home | Next
OCIPLogon | Up | OCILogOff