Back to index

php5  5.3.10
drcp_functions.inc
Go to the documentation of this file.
00001 <?php
00002 
00003 /* This file contains functions required by the DRCP tests */
00004 
00005 function drcp_create_table($conn)
00006 {
00007        $create_sql = "CREATE TABLE DRCPTEST (id NUMBER, name VARCHAR2(10), dept VARCHAR2(10))";
00008        $statement = oci_parse($conn, $create_sql);
00009        oci_execute($statement);
00010        
00011        $id_values = array(100,101,102,103,104,105,106,107,108);
00012        $name_values = array("WIILIAMS","JOHN","SMITH","JONES","ADAMS","ROBERT",
00013                                            "BILL","LAWSON","MARY");
00014        $dept_values = array("ACCOUNTS","HR","HR","ADMIN","ACCOUNTS","HR",
00015                                            "ACCOUNTS","HR","ACCOUNTS");
00016        for($i=0; $i<8; $i++) {
00017               $insert = "INSERT INTO DRCPTEST VALUES(".$id_values[$i].",'". $name_values[$i]."','".$dept_values[$i]."')";
00018               $s = oci_parse($conn, $insert);
00019               oci_execute($s);
00020        }      
00021 }
00022 
00023 function drcp_drop_table($conn)
00024 {
00025        $ora_sql = "DROP TABLE DRCPTEST";
00026        $statement = oci_parse($conn, $ora_sql);
00027        oci_execute($statement);
00028 }
00029 
00030 function drcp_update_table($conn)
00031 {
00032        $update_stmt ="Update drcptest set dept ='NEWDEPT' where id = 105";
00033        $s1 = oci_parse($conn,$update_stmt);
00034        oci_execute($s1,OCI_DEFAULT);
00035        echo "Update done-- DEPT value has been set to NEWDEPT\n";
00036 }
00037 
00038 function drcp_select_value($conn)
00039 {
00040        $sel_stmt="select dept from drcptest where id=105";
00041        $s2 = oci_parse($conn,$sel_stmt);
00042        oci_execute($s2,OCI_DEFAULT);
00043        while(oci_fetch($s2)) {
00044               echo "The value of DEPT for id 105 is ".oci_result($s2,1)."\n";
00045        }
00046 }
00047 
00048 function drcp_select_packagevar($conn)
00049 {
00050        $sel_stmt="select drcp_test_package.f1 as f1 from dual";
00051        $s2 = oci_parse($conn, $sel_stmt);
00052        oci_define_by_name($s2,'f1',$ret_num);
00053        oci_execute($s2);
00054        while(oci_fetch($s2)) {
00055               echo " The value of the package variable is ".oci_result($s2,1)."\n";
00056        }
00057 }
00058 
00059 
00060 function drcp_set_packagevar($conn,$num)
00061 {
00062        $set_stmt = "begin drcp_test_package.p1($num); end;";
00063        $s1 = oci_parse($conn,$set_stmt);
00064        oci_execute($s1);
00065        echo " Package variable value set to " .$num."\n";
00066 }
00067 
00068 function drcp_create_package($c)
00069 {
00070        $create_package_stmt = "create or replace package drcp_test_package as
00071                      var int :=0;
00072                      procedure p1(var1 int);
00073                      function f1 return number;
00074                      end;";
00075        $s1 = oci_parse($c, $create_package_stmt);
00076        oci_execute($s1);
00077        
00078        $package_body = "create or replace package body drcp_test_package as
00079               procedure p1(var1 int) is
00080               begin
00081               var :=var1;
00082               end;   
00083               function f1 return number is
00084               begin
00085               return drcp_test_package.var;
00086               end;
00087               end;";
00088 
00089        $s2 = oci_parse($c, $package_body);
00090        oci_execute($s2);
00091 }
00092 
00093 ?>