xref: /PHP-8.3/ext/oci8/tests/cursors.phpt (revision a53e5617)
1--TEST--
2fetching 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";
15require __DIR__."/create_table.inc";
16
17$insert_sql = "INSERT INTO ".$schema.$table_name." (id, value) VALUES (1,1)";
18
19if (!($s = oci_parse($c, $insert_sql))) {
20    die("oci_parse(insert) failed!\n");
21}
22
23for ($i = 0; $i<3; $i++) {
24    if (!oci_execute($s)) {
25        die("oci_execute(insert) failed!\n");
26    }
27}
28
29if (!oci_commit($c)) {
30    die("oci_commit() failed!\n");
31}
32
33$sql = "select CURSOR(select * from ".$schema.$table_name.") as curs FROM dual";
34$stmt = oci_parse($c, $sql);
35
36oci_execute($stmt);
37
38while ($data = oci_fetch_assoc($stmt)) {
39    oci_execute($data["CURS"]);
40    $subdata = oci_fetch_assoc($data["CURS"]);
41    var_dump($subdata);
42    var_dump(oci_cancel($data["CURS"]));
43    $subdata = oci_fetch_assoc($data["CURS"]);
44    var_dump($subdata);
45    var_dump(oci_cancel($data["CURS"]));
46}
47
48require __DIR__."/drop_table.inc";
49
50echo "Done\n";
51
52?>
53--EXPECTF--
54array(5) {
55  ["ID"]=>
56  string(1) "1"
57  ["VALUE"]=>
58  string(1) "1"
59  ["BLOB"]=>
60  NULL
61  ["CLOB"]=>
62  NULL
63  ["STRING"]=>
64  NULL
65}
66bool(true)
67
68Warning: oci_fetch_assoc(): ORA-01002: fetch out of sequence in %s on line %d
69bool(false)
70bool(true)
71Done
72