array_bind_int1.phpt 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. --TEST--
  2. oci_bind_array_by_name() and SQLT_INT
  3. --SKIPIF--
  4. <?php
  5. $target_dbs = array('oracledb' => true, 'timesten' => false); // test runs on these DBs
  6. require(dirname(__FILE__).'/skipif.inc');
  7. ?>
  8. --FILE--
  9. <?php
  10. require dirname(__FILE__).'/connect.inc';
  11. $drop = "DROP table bind_test";
  12. $statement = oci_parse($c, $drop);
  13. @oci_execute($statement);
  14. $create = "CREATE table bind_test(name NUMBER)";
  15. $statement = oci_parse($c, $create);
  16. oci_execute($statement);
  17. $create_pkg = "
  18. CREATE OR REPLACE PACKAGE ARRAY_BIND_INT1_PKG AS
  19. TYPE ARRTYPE IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
  20. PROCEDURE iobind(c1 IN OUT ARRTYPE);
  21. END ARRAY_BIND_INT1_PKG;";
  22. $statement = oci_parse($c, $create_pkg);
  23. oci_execute($statement);
  24. $create_pkg_body = "
  25. CREATE OR REPLACE PACKAGE BODY ARRAY_BIND_INT1_PKG AS
  26. CURSOR CUR IS SELECT name FROM bind_test;
  27. PROCEDURE iobind(c1 IN OUT ARRTYPE) IS
  28. BEGIN
  29. FOR i IN 1..5 LOOP
  30. INSERT INTO bind_test VALUES (c1(i));
  31. END LOOP;
  32. IF NOT CUR%ISOPEN THEN
  33. OPEN CUR;
  34. END IF;
  35. FOR i IN REVERSE 1..5 LOOP
  36. FETCH CUR INTO c1(i);
  37. IF CUR%NOTFOUND THEN
  38. CLOSE CUR;
  39. EXIT;
  40. END IF;
  41. END LOOP;
  42. END iobind;
  43. END ARRAY_BIND_INT1_PKG;";
  44. $statement = oci_parse($c, $create_pkg_body);
  45. oci_execute($statement);
  46. $statement = oci_parse($c, "BEGIN array_bind_int1_pkg.iobind(:c1); END;");
  47. $array = Array(1,2,3,4,5);
  48. oci_bind_array_by_name($statement, ":c1", $array, 10, 5, SQLT_INT);
  49. oci_execute($statement);
  50. var_dump($array);
  51. echo "Done\n";
  52. ?>
  53. --EXPECT--
  54. array(5) {
  55. [0]=>
  56. int(5)
  57. [1]=>
  58. int(4)
  59. [2]=>
  60. int(3)
  61. [3]=>
  62. int(2)
  63. [4]=>
  64. int(1)
  65. }
  66. Done