drcp_functions.inc 2.6 KB

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