conn_attr.inc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. require(dirname(__FILE__)."/connect.inc");
  3. preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches);
  4. if ((isset($matches[1]) && $matches[1] >= 11)) {
  5. // Server is Oracle 11.2+
  6. $stmtarray = array(
  7. "drop user $testuser cascade",
  8. "create user $testuser identified by $testpassword", // $testuser should be set by the file that includes conn_attr.inc
  9. "grant connect,resource,dba to $testuser",
  10. "alter user $testuser enable editions",
  11. "drop edition myedition1 cascade",
  12. "drop edition myedition cascade",
  13. "grant create any edition to $testuser",
  14. "create edition myedition",
  15. "create edition myedition1 as child of myedition",
  16. "grant use on edition myedition to $testuser",
  17. "grant use on edition myedition1 to $testuser",
  18. );
  19. } else {
  20. // Server is Pre 11.2
  21. $stmtarray = array(
  22. "drop user $testuser cascade",
  23. "create user $testuser identified by $testpassword",
  24. "grant connect,resource,dba to $testuser",
  25. );
  26. }
  27. foreach ($stmtarray as $stmt) {
  28. $s = oci_parse($c, $stmt);
  29. $r = @oci_execute($s);
  30. if (!$r) {
  31. $m = oci_error($s);
  32. if (!in_array($m['code'], array( // ignore expected errors
  33. 942 // table or view does not exist
  34. , 1918 // user does not exist
  35. , 2289 // sequence does not exist
  36. , 4080 // trigger does not exist
  37. , 38802 // edition does not exist
  38. ))) {
  39. echo "Error:" . $stmt . PHP_EOL . $m['message'] . PHP_EOL;
  40. if ($m['code'] == 38807) {
  41. echo "You appear to already have an edition in use that prevents this PHP test from running. Query DBA_EDITIONS to see existing editions.". PHP_EOL;
  42. }
  43. die;
  44. }
  45. }
  46. }
  47. function get_attr($conn,$attr)
  48. {
  49. $sel_stmt="select " .$attr. " from v\$session where sid =
  50. (select sid from v\$session where audsid =
  51. sys_context('userenv','sessionid')) order by 1";
  52. $s2 = oci_parse($conn,$sel_stmt);
  53. oci_execute($s2,OCI_DEFAULT);
  54. while (oci_fetch($s2)) {
  55. echo "The value of ".$attr ." is ".oci_result($s2,1)."\n";
  56. }
  57. }
  58. /* Pass $conn_type=1 for a connection with oci_connect()
  59. Pass $conn_type=2 for ooci_pconnect
  60. Default will give a oci_new_connect */
  61. function get_conn($conn_type)
  62. {
  63. $user = $GLOBALS['testuser'];
  64. $password = $GLOBALS['testpassword'];
  65. $dbase = $GLOBALS['dbase'];
  66. switch($conn_type) {
  67. case 1:
  68. echo "Testing with oci_connect()\n";
  69. return(oci_connect($user,$password,$dbase));
  70. break;
  71. case 2:
  72. echo "Testing with oci_pconnect()\n";
  73. return(oci_pconnect($user,$password,$dbase));
  74. break;
  75. default:
  76. echo "Testing with oci_new_connect()\n";
  77. return(oci_new_connect($user,$password,$dbase));
  78. break;
  79. }
  80. }
  81. function set_attr($conn,$attr,$sufix)
  82. {
  83. if (!strcmp($attr,'MODULE'))
  84. $r = oci_set_module_name($conn,'PHP TEST'.$sufix);
  85. else if (!strcmp($attr,'ACTION'))
  86. $r = oci_set_action($conn,'TASK'.$sufix);
  87. else if (!strcmp($attr,'CLIENT_INFO'))
  88. $r = oci_set_client_info($conn,'INFO1'.$sufix);
  89. else if (!strcmp($attr,'CLIENT_IDENTIFIER'))
  90. $r = oci_set_client_identifier($conn,'ID00'.$sufix);
  91. else
  92. echo "Pass one of the above four attributes!!!\n";
  93. if ($r) {
  94. echo "Value of $attr has been set successfully\n";
  95. }
  96. //Do a round-trip here
  97. oci_server_version($conn);
  98. return $r;
  99. }
  100. function set_edit_attr($value)
  101. {
  102. $r = oci_set_edition($value);
  103. if ($r) {
  104. echo " The value of edition has been successfully set\n";
  105. }
  106. return $r;
  107. }
  108. function get_edit_attr ($conn) {
  109. $sel_stmt = "select sys_context('USERENV', 'CURRENT_EDITION_NAME') from dual";
  110. $s2 = oci_parse($conn,$sel_stmt);
  111. oci_execute($s2,OCI_DEFAULT);
  112. while (oci_fetch($s2)) {
  113. echo "The value of current EDITION is ".oci_result($s2,1)."\n";
  114. }
  115. }
  116. function get_sys_attr($conn,$attr)
  117. {
  118. $sel_stmt="select " .$attr. " from v\$session where sid =
  119. (select sid from v\$session where audsid = sys_context('userenv','sessionid')) order by 1";
  120. $s2 = oci_parse($conn,$sel_stmt);
  121. oci_execute($s2,OCI_DEFAULT);
  122. while (oci_fetch($s2)) {
  123. echo "The value of ".$attr ." is ".oci_result($s2,1)."\n";
  124. }
  125. }
  126. function clean_up($c) {
  127. $stmtarray = array(
  128. "drop edition myedition1 cascade",
  129. "drop edition myedition cascade",
  130. "drop user " . $GLOBALS['testuser'] . " cascade",
  131. );
  132. foreach ($stmtarray as $stmt) {
  133. $s = oci_parse($c, $stmt);
  134. @oci_execute($s);
  135. }
  136. }