cursor_bind.phpt 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. --TEST--
  2. bind and fetch cursor from a statement
  3. --EXTENSIONS--
  4. oci8
  5. --SKIPIF--
  6. <?php
  7. $target_dbs = array('oracledb' => true, 'timesten' => false); // test runs on these DBs
  8. require(__DIR__.'/skipif.inc');
  9. ?>
  10. --FILE--
  11. <?php
  12. require(__DIR__."/connect.inc");
  13. // Initialization
  14. $stmtarray = array(
  15. "drop table cursor_bind_tab",
  16. "create table cursor_bind_tab (id NUMBER, value VARCHAR(20))",
  17. "insert into cursor_bind_tab values (1, '1')",
  18. "insert into cursor_bind_tab values (1, '1')",
  19. "insert into cursor_bind_tab values (1, '1')"
  20. );
  21. oci8_test_sql_execute($c, $stmtarray);
  22. $sql = "
  23. DECLARE
  24. TYPE curtype IS REF CURSOR;
  25. cursor_var curtype;
  26. BEGIN
  27. OPEN cursor_var FOR SELECT id, value FROM cursor_bind_tab;
  28. :curs := cursor_var;
  29. END;
  30. ";
  31. $stmt = oci_parse($c, $sql);
  32. $cursor = oci_new_cursor($c);
  33. oci_bind_by_name($stmt, ":curs", $cursor, -1, OCI_B_CURSOR);
  34. oci_execute($stmt);
  35. oci_execute($cursor);
  36. var_dump(oci_fetch_row($cursor));
  37. var_dump(oci_fetch_row($cursor));
  38. var_dump(oci_fetch_row($cursor));
  39. var_dump(oci_fetch_row($cursor));
  40. // Clean up
  41. $stmtarray = array(
  42. "drop table cursor_bind_tab"
  43. );
  44. oci8_test_sql_execute($c, $stmtarray);
  45. ?>
  46. --EXPECT--
  47. array(2) {
  48. [0]=>
  49. string(1) "1"
  50. [1]=>
  51. string(1) "1"
  52. }
  53. array(2) {
  54. [0]=>
  55. string(1) "1"
  56. [1]=>
  57. string(1) "1"
  58. }
  59. array(2) {
  60. [0]=>
  61. string(1) "1"
  62. [1]=>
  63. string(1) "1"
  64. }
  65. bool(false)