xref: /PHP-8.3/ext/oci8/tests/array_bind_014.phpt (revision a53e5617)
1--TEST--
2oci_bind_array_by_name() and NUMBERs
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$drop = "DROP table bind_test";
17$statement = oci_parse($c, $drop);
18@oci_execute($statement);
19
20$create = "CREATE table bind_test(name NUMBER)";
21$statement = oci_parse($c, $create);
22oci_execute($statement);
23
24$create_pkg = "
25CREATE OR REPLACE PACKAGE ARRAY_BIND_014_PKG AS
26  TYPE ARRTYPE IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
27  PROCEDURE iobind(c1 IN OUT ARRTYPE);
28END ARRAY_BIND_014_PKG;";
29$statement = oci_parse($c, $create_pkg);
30oci_execute($statement);
31
32$create_pkg_body = "
33CREATE OR REPLACE PACKAGE BODY ARRAY_BIND_014_PKG AS
34  CURSOR CUR IS SELECT name FROM bind_test;
35  PROCEDURE iobind(c1 IN OUT ARRTYPE) IS
36    BEGIN
37    IF NOT CUR%ISOPEN THEN
38      OPEN CUR;
39    END IF;
40    FOR i IN REVERSE 1..5 LOOP
41      FETCH CUR INTO c1(i);
42      IF CUR%NOTFOUND THEN
43        CLOSE CUR;
44        EXIT;
45      END IF;
46    END LOOP;
47  END iobind;
48END ARRAY_BIND_014_PKG;";
49$statement = oci_parse($c, $create_pkg_body);
50oci_execute($statement);
51
52for ($i = 1; $i < 6; $i++) {
53    $statement = oci_parse($c, "INSERT INTO bind_test VALUES (".$i.")");
54    oci_execute($statement);
55}
56
57$statement = oci_parse($c, "BEGIN array_bind_014_pkg.iobind(:c1); END;");
58$array = Array();
59oci_bind_array_by_name($statement, ":c1", $array, 5, -1, SQLT_INT);
60oci_execute($statement);
61
62var_dump($array);
63
64echo "Done\n";
65?>
66--EXPECT--
67array(5) {
68  [0]=>
69  int(5)
70  [1]=>
71  int(4)
72  [2]=>
73  int(3)
74  [3]=>
75  int(2)
76  [4]=>
77  int(1)
78}
79Done
80