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