bug71148.phpt 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. --TEST--
  2. Bug #71448 (Binding reference overwritten on php7)
  3. --EXTENSIONS--
  4. oci8
  5. --SKIPIF--
  6. <?php
  7. $target_dbs = array('oracledb' => true, 'timesten' => true); // test runs on these DBs
  8. require(__DIR__.'/skipif.inc');
  9. ?>
  10. --FILE--
  11. <?php
  12. require(__DIR__.'/connect.inc');
  13. // Initialize
  14. $stmtarray = array(
  15. "CREATE OR REPLACE FUNCTION bindfunc(var1 varchar2, var2 varchar2)
  16. RETURN varchar2
  17. AS var3 VARCHAR2(20);
  18. BEGIN
  19. var3 := CONCAT(var1, var2);
  20. RETURN var3;
  21. END;",
  22. "CREATE OR REPLACE PROCEDURE bindproc(var1 IN string, var2 IN string, var3 IN OUT string) IS
  23. BEGIN
  24. var3 := CONCAT(var1, var3);
  25. var3 := CONCAT(var3, var2);
  26. END;"
  27. );
  28. oci8_test_sql_execute($c, $stmtarray);
  29. // Run test
  30. function bindvar($stmt, $name, $var)
  31. {
  32. oci_bind_by_name($stmt, $name, $var);
  33. }
  34. // Test 1: Bind input parameter in a local function
  35. $sql = "select :var1, :var2 from dual";
  36. $cache1 = "INSTR1";
  37. $cache2 = "INSTR2";
  38. echo "Test 1: Bind input parameter in a local function\n";
  39. $stmt = oci_parse($c, $sql);
  40. bindvar($stmt, ':var1', $cache1);
  41. bindvar($stmt, ':var2', $cache2);
  42. oci_execute($stmt);
  43. var_dump(oci_fetch_assoc($stmt));
  44. oci_free_statement($stmt);
  45. // Test 2: Bind output parameter in a local function
  46. $sql = "begin :output1 := 'OUTSTR1'; :output2 := 'OUTSTR2'; end;";
  47. $cache1 = "xxxxxx";
  48. $cache2 = "xxxxxx";
  49. echo "\nTest 2: Bind output parameter in a local function\n";
  50. $stmt = oci_parse($c, $sql);
  51. bindvar($stmt, ':output1', $cache1);
  52. bindvar($stmt, ':output2', $cache2);
  53. oci_execute($stmt);
  54. var_dump($cache1);
  55. var_dump($cache2);
  56. oci_free_statement($stmt);
  57. // Test 3: Bind output parameter within the same scope of execute
  58. $sql = "begin :output1 := 'OUTSTR1'; :output2 := 'OUTSTR2'; end;";
  59. $cache1 = "xxxxxx";
  60. $cache2 = "xxxxxx";
  61. echo "\nTest 3: Bind output parameter within the same scope of execute\n";
  62. $stmt = oci_parse($c, $sql);
  63. oci_bind_by_name($stmt, ":output1", $cache1);
  64. oci_bind_by_name($stmt, ":output2", $cache2);
  65. oci_execute($stmt);
  66. var_dump($cache1);
  67. var_dump($cache2);
  68. oci_free_statement($stmt);
  69. // Test 4: Bind output parameter within the same scope of execute
  70. $sql= "begin :output := bindfunc(:var1, :var2); end;";
  71. $cache1 = "STR1";
  72. $cache2 = "STR2";
  73. echo "\nTest 4: Bind output parameter within the same scope of execute\n";
  74. $stmt = oci_parse($c, $sql);
  75. oci_bind_by_name($stmt, ":var1", $cache1, -1);
  76. oci_bind_by_name($stmt, ":var2", $cache2, -1);
  77. oci_bind_by_name($stmt, ":output", $cache3, 100);
  78. oci_execute($stmt);
  79. var_dump($cache3);
  80. // Test 5: Bind IN OUT parameter in a local function
  81. $sql = "call bindproc(:var1, :var2, :var3)";
  82. $cache1 = 'STR1';
  83. $cache2 = 'STR2';
  84. $cache3 = ' ';
  85. echo "\nTest 5: Bind IN OUT parameter in a local function\n";
  86. $stmt = oci_parse($c, $sql);
  87. bindvar($stmt, ':var1', $cache1);
  88. bindvar($stmt, ':var2', $cache2);
  89. bindvar($stmt, ':var3', $cache3);
  90. oci_execute($stmt);
  91. var_dump($cache1);
  92. var_dump($cache2);
  93. var_dump($cache3);
  94. oci_free_statement($stmt);
  95. // Test 6: Bind IN OUT parameter within the same scope of execute
  96. $sql = "call bindproc(:var1, :var2, :var3)";
  97. $cache1 = 'STR1';
  98. $cache2 = 'STR2';
  99. $cache3 = ' ';
  100. echo "\nTest 6: Bind IN OUT parameter within the same scope of execute\n";
  101. $stmt = oci_parse($c, $sql);
  102. oci_bind_by_name($stmt, ":var1", $cache1, -1);
  103. oci_bind_by_name($stmt, ":var2", $cache2, -1);
  104. oci_bind_by_name($stmt, ":var3", $cache3, 100);
  105. oci_execute($stmt);
  106. var_dump($cache1);
  107. var_dump($cache2);
  108. var_dump($cache3);
  109. // Cleanup
  110. $stmtarray = array(
  111. "DROP FUNCTION bindfunc",
  112. "DROP PROCEDURE bindproc"
  113. );
  114. oci8_test_sql_execute($c, $stmtarray);
  115. ?>
  116. --EXPECT--
  117. Test 1: Bind input parameter in a local function
  118. array(2) {
  119. [":VAR1"]=>
  120. string(6) "INSTR1"
  121. [":VAR2"]=>
  122. string(6) "INSTR2"
  123. }
  124. Test 2: Bind output parameter in a local function
  125. string(6) "xxxxxx"
  126. string(6) "xxxxxx"
  127. Test 3: Bind output parameter within the same scope of execute
  128. string(7) "OUTSTR1"
  129. string(7) "OUTSTR2"
  130. Test 4: Bind output parameter within the same scope of execute
  131. string(8) "STR1STR2"
  132. Test 5: Bind IN OUT parameter in a local function
  133. string(4) "STR1"
  134. string(4) "STR2"
  135. string(1) " "
  136. Test 6: Bind IN OUT parameter within the same scope of execute
  137. string(4) "STR1"
  138. string(4) "STR2"
  139. string(9) "STR1 STR2"