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