xref: /PHP-8.1/ext/oci8/tests/array_bind_002.phpt (revision 74859783)
1--TEST--
2oci_bind_array_by_name() and invalid values 2
3--EXTENSIONS--
4oci8
5--FILE--
6<?php
7
8require __DIR__.'/connect.inc';
9
10$drop = "DROP table bind_test";
11$statement = oci_parse($c, $drop);
12@oci_execute($statement);
13
14$create = "CREATE table bind_test(name DATE)";
15$statement = oci_parse($c, $create);
16oci_execute($statement);
17
18$create_pkg = "
19CREATE OR REPLACE PACKAGE ARRAY_BIND_002_PKG AS
20  TYPE ARRTYPE IS TABLE OF DATE INDEX BY BINARY_INTEGER;
21  PROCEDURE iobind(c1 IN OUT ARRTYPE);
22END ARRAY_BIND_002_PKG;";
23$statement = oci_parse($c, $create_pkg);
24oci_execute($statement);
25
26$create_pkg_body = "
27CREATE OR REPLACE PACKAGE BODY ARRAY_BIND_002_PKG AS
28  CURSOR CUR IS SELECT name FROM bind_test;
29  PROCEDURE iobind(c1 IN OUT ARRTYPE) IS
30    BEGIN
31    FOR i IN 1..5 LOOP
32      INSERT INTO bind_test VALUES (c1(i));
33    END LOOP;
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_002_PKG;";
46$statement = oci_parse($c, $create_pkg_body);
47oci_execute($statement);
48
49$statement = oci_parse($c, "BEGIN array_bind_002_pkg.iobind(:c1); END;");
50
51$array = Array("06-DEC-05","10-DEC-80","21-AUG-91","26-OCT-17","05-NOV-05");
52
53try {
54    oci_bind_array_by_name($statement, ":c1", $array, 0, 0, SQLT_ODT);
55} catch (ValueError $e) {
56    echo $e->getMessage(), "\n";
57}
58
59oci_execute($statement);
60
61var_dump($array);
62
63echo "Done\n";
64?>
65--EXPECTF--
66oci_bind_array_by_name(): Argument #4 ($max_array_length) must be greater than 0
67
68Warning: oci_execute(): ORA-%r(01008|57000)%r: %s in %s on line %d
69array(5) {
70  [0]=>
71  string(9) "06-DEC-05"
72  [1]=>
73  string(9) "10-DEC-80"
74  [2]=>
75  string(9) "21-AUG-91"
76  [3]=>
77  string(9) "26-OCT-17"
78  [4]=>
79  string(9) "05-NOV-05"
80}
81Done
82