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