<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.oci-bind-array-by-name" xmlns="http://docbook.org/ns/docbook">
 <refnamediv>
  <refname>oci_bind_array_by_name</refname>
  <refpurpose>Binds PHP array to Oracle PL/SQL array by name</refpurpose>
 </refnamediv>
 
 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <type>bool</type><methodname>oci_bind_array_by_name</methodname>
   <methodparam><type>resource</type><parameter>statement</parameter></methodparam>
   <methodparam><type>string</type><parameter>name</parameter></methodparam>
   <methodparam><type>array</type><parameter role="reference">var_array</parameter></methodparam>
   <methodparam><type>int</type><parameter>max_table_length</parameter></methodparam>
   <methodparam choice="opt"><type>int</type><parameter>max_item_length</parameter><initializer>-1</initializer></methodparam>
   <methodparam choice="opt"><type>int</type><parameter>type</parameter><initializer>SQLT_AFC</initializer></methodparam>
  </methodsynopsis>
  <para>
   Binds the PHP array <parameter>var_array</parameter> to the Oracle
   placeholder <parameter>name</parameter>, which points to Oracle PL/SQL
   array. Whether it will be used for input or output will be determined at
   run-time. 
  </para>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    <varlistentry>
     <term><parameter>statement</parameter></term>
     <listitem>
      <para>
       A valid OCI statement identifier.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>name</parameter></term>
     <listitem>
      <para>
       The Oracle placeholder.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>var_array</parameter></term>
     <listitem>
      <para>
       An array.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>max_table_length</parameter></term>
     <listitem>
      <para>
       Sets the maximum length both for incoming and result arrays.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>max_item_length</parameter></term>
     <listitem>
      <para>
       Sets maximum length for array items. If not specified or equals to -1,
       <function>oci_bind_array_by_name</function> will use find the longest
       element in the incoming array and will use it as maximum length for
       array items.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>type</parameter></term>
     <listitem>
      <para>
       Should be used to set the type of PL/SQL array items. See list of
       available types below:
      </para>
      <para>
       <itemizedlist>
        <listitem>
         <para>
          <constant>SQLT_NUM</constant> - for arrays of NUMBER.
         </para>
        </listitem>
        <listitem>
         <para>
          <constant>SQLT_INT</constant> - for arrays of INTEGER (Note: INTEGER
          it is actually a synonym for NUMBER(38), but
          <constant>SQLT_NUM</constant> type won't work in this case even
          though they are synonyms).
         </para>
        </listitem>
        <listitem>
         <para>
          <constant>SQLT_FLT</constant> - for arrays of FLOAT.
         </para>
        </listitem>
        <listitem>
         <para>
          <constant>SQLT_AFC</constant> - for arrays of CHAR.
         </para>
        </listitem>
        <listitem>
         <para>
          <constant>SQLT_CHR</constant> - for arrays of VARCHAR2.
         </para>
        </listitem>
        <listitem>
         <para>
          <constant>SQLT_VCS</constant> - for arrays of VARCHAR.
         </para>
        </listitem>
        <listitem>
         <para>
          <constant>SQLT_AVC</constant> - for arrays of CHARZ.
         </para>
        </listitem>
        <listitem>
         <para>
          <constant>SQLT_STR</constant> - for arrays of STRING.
         </para>
        </listitem>
        <listitem>
         <para>
          <constant>SQLT_LVC</constant> - for arrays of LONG VARCHAR.
         </para>
        </listitem>
       <listitem>
         <para>
          <constant>SQLT_ODT</constant> - for arrays of DATE.
         </para>
        </listitem>
       </itemizedlist>
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   &return.success;
  </para>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <para>
   <example>
    <title><function>oci_bind_array_by_name</function> example</title>
    <programlisting role="php">
<![CDATA[
<?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);

?>
]]>
    </programlisting>
   </example>
  </para>
 </refsect1>

 <refsect1 role="notes">
  &reftitle.notes;
  <note>
   <para>
    This function is available since OCI8 release 1.2.
   </para>
  </note>
 </refsect1>

</refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->