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