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