xref: /PHP-5.5/ext/oci8/tests/drcp_functions.inc (revision c7a8bd6a)
1<?php
2
3/* This file contains functions required by the DRCP tests */
4
5function drcp_create_table($conn)
6{
7	$create_sql = "CREATE TABLE DRCPTEST (id NUMBER, name VARCHAR2(10), dept VARCHAR2(10))";
8	$statement = oci_parse($conn, $create_sql);
9	oci_execute($statement);
10
11	$id_values = array(100,101,102,103,104,105,106,107,108);
12	$name_values = array("WIILIAMS","JOHN","SMITH","JONES","ADAMS","ROBERT",
13						 "BILL","LAWSON","MARY");
14	$dept_values = array("ACCOUNTS","HR","HR","ADMIN","ACCOUNTS","HR",
15						 "ACCOUNTS","HR","ACCOUNTS");
16	for($i=0; $i<8; $i++) {
17		$insert = "INSERT INTO DRCPTEST VALUES(".$id_values[$i].",'". $name_values[$i]."','".$dept_values[$i]."')";
18		$s = oci_parse($conn, $insert);
19		oci_execute($s);
20	}
21}
22
23function drcp_drop_table($conn)
24{
25	$ora_sql = "DROP TABLE DRCPTEST";
26	$statement = oci_parse($conn, $ora_sql);
27	oci_execute($statement);
28}
29
30function drcp_update_table($conn)
31{
32	$update_stmt ="Update drcptest set dept ='NEWDEPT' where id = 105";
33	$s1 = oci_parse($conn,$update_stmt);
34	oci_execute($s1,OCI_DEFAULT);
35	echo "Update done-- DEPT value has been set to NEWDEPT\n";
36}
37
38function drcp_select_value($conn)
39{
40	$sel_stmt="select dept from drcptest where id=105";
41	$s2 = oci_parse($conn,$sel_stmt);
42	oci_execute($s2,OCI_DEFAULT);
43	while(oci_fetch($s2)) {
44		echo "The value of DEPT for id 105 is ".oci_result($s2,1)."\n";
45	}
46}
47
48function drcp_select_packagevar($conn)
49{
50	$sel_stmt="select drcp_test_package.f1 as f1 from dual";
51	$s2 = oci_parse($conn, $sel_stmt);
52	oci_define_by_name($s2,'f1',$ret_num);
53	oci_execute($s2);
54	while(oci_fetch($s2)) {
55		echo " The value of the package variable is ".oci_result($s2,1)."\n";
56	}
57}
58
59
60function drcp_set_packagevar($conn,$num)
61{
62	$set_stmt = "begin drcp_test_package.p1($num); end;";
63	$s1 = oci_parse($conn,$set_stmt);
64	oci_execute($s1);
65	echo " Package variable value set to " .$num."\n";
66}
67
68function drcp_create_package($c)
69{
70	$create_package_stmt = "create or replace package drcp_test_package as
71			var int :=0;
72	 		procedure p1(var1 int);
73			function f1 return number;
74			end;";
75	$s1 = oci_parse($c, $create_package_stmt);
76	oci_execute($s1);
77
78	$package_body = "create or replace package body drcp_test_package as
79		procedure p1(var1 int) is
80		begin
81		var :=var1;
82		end;
83		function f1 return number is
84		begin
85		return drcp_test_package.var;
86		end;
87		end;";
88
89	$s2 = oci_parse($c, $package_body);
90	oci_execute($s2);
91}
92
93?>
94