oci_bind_array_by_name

(no version information, might be only in CVS)

oci_bind_array_by_name --  Binds PHP array to Oracle PL/SQL array by name

Description

bool oci_bind_array_by_name ( resource stmt, string name, array &var_array, int max_table_length [, int max_item_length [, int type]] )

Note: This function is available since OCI8 release 1.2 and PHP release 5.1.2.

oci_bind_array_by_name() binds the PHP array var_array to the Oracle placeholder name, which points to Oracle PL/SQL array. Whether it will be used for input or output will be determined at run-time. The max_table_length parameter sets the maximum length both for incoming and result arrays. Parameter max_item_length sets maximum length for array items. If max_item_length was not specified or equals to -1, oci_bind_array_by_name() will use find the longest element in the incoming array and will use it as maximum length for array items. type parameter should be used to set the type of PL/SQL array items. See list of available types below.

Example 1. oci_bind_array_by_name()example

<?php

$c
= oci_connect("scott", "tiger");

$create = "CREATE TABLE bind_example(name VARCHAR(20))";
$statement = oci_parse($c, $create);
oci_execute($statement);

$create_pkg = "
CREATE OR REPLACE PACKAGE ARRAYBINDPKG1 AS
  TYPE ARRTYPE IS TABLE OF VARCHAR(20) INDEX BY BINARY_INTEGER;
  PROCEDURE iobind(c1 IN OUT ARRTYPE);
END ARRAYBINDPKG1;"
;
$statement = oci_parse($c, $create_pkg);
oci_execute($statement);

$create_pkg_body = "
CREATE OR REPLACE PACKAGE BODY ARRAYBINDPKG1 AS
  CURSOR CUR IS SELECT name FROM bind_example;
  PROCEDURE iobind(c1 IN OUT ARRTYPE) IS
    BEGIN
    FOR i IN 1..5 LOOP
      INSERT INTO bind_example VALUES (c1(i));
    END LOOP;
    IF NOT CUR%ISOPEN THEN
      OPEN CUR;
    END IF;
    FOR i IN REVERSE 1..5 LOOP
      FETCH CUR INTO c1(i);
      IF CUR%NOTFOUND THEN
        CLOSE CUR;
        EXIT;
      END IF;
    END LOOP;
  END iobind;
END ARRAYBINDPKG1;"
;
$statement = oci_parse($c, $create_pkg_body);
oci_execute($statement);

$statement = oci_parse($c, "BEGIN ARRAYBINDPKG1.iobind(:c1); END;");

$array = array("one", "two", "three", "four", "five");

oci_bind_array_by_name($statement, ":c1", $array, 5, -1, SQLT_CHR);

oci_execute($statement);

var_dump($array);

?>