<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.oci-error" xmlns="http://docbook.org/ns/docbook">
 <refnamediv>
  <refname>oci_error</refname>
  <refpurpose>Returns the last error found</refpurpose>
 </refnamediv>
 
 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <type class="union"><type>array</type><type>false</type></type><methodname>oci_error</methodname>
   <methodparam choice="opt"><type class="union"><type>resource</type><type>null</type></type><parameter>connection_or_statement</parameter><initializer>&null;</initializer></methodparam>
  </methodsynopsis>
  <para>
   Returns the last error found.
  </para>
  <para>
   The function should be called immediately after an error occurs.
   Errors are cleared by a successful statement.
  </para>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    <varlistentry>
     <term><parameter>connection_or_statement</parameter></term>
     <listitem>
      <para>
       For most errors, <parameter>connection_or_statement</parameter> is the
       resource handle that was passed to the failing function call.
       For connection errors with <function>oci_connect</function>,
       <function>oci_new_connect</function> or 
       <function>oci_pconnect</function> &null; should be passed.
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   If no error is found, <function>oci_error</function> returns
   &false;. Otherwise, <function>oci_error</function> returns the
   error information as an associative array.
  </para>
  <para>
   <table>
   <title><function>oci_error</function> Array Description</title>

    <tgroup cols="3">
     <thead>
      <row>
       <entry>Array key</entry>
       <entry>Type</entry>
       <entry>&Description;</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry><literal>code</literal></entry>
       <entry><type>int</type></entry>
       <entry>
         The Oracle error number.
       </entry>
      </row>
      <row>
       <entry><literal>message</literal></entry>
       <entry><type>string</type></entry>
       <entry>
         The Oracle error text.
       </entry>
      </row>
      <row>
       <entry><literal>offset</literal></entry>
       <entry><type>int</type></entry>
       <entry>
         The byte position of an error in the SQL statement.  If there
         was no statement, this is <literal>0</literal>
       </entry>
      </row>
      <row>
       <entry><literal>sqltext</literal></entry>
       <entry><type>string</type></entry>
       <entry>
         The SQL statement text.  If there was no statement, this is
         an empty string.
       </entry>
      </row>
     </tbody>
    </tgroup>
   </table>
  </para>
 </refsect1>

 <refsect1 role="changelog">
  &reftitle.changelog;
  <informaltable>
   <tgroup cols="2">
    <thead>
     <row>
      <entry>&Version;</entry>
      <entry>&Description;</entry>
     </row>
    </thead>
    <tbody>
     <row>
      <entry>8.0.0, PECL OCI8 3.0.0</entry>
      <entry>
       <parameter>connection_or_statement</parameter> is now nullable.
      </entry>
     </row>
    </tbody>
   </tgroup>
  </informaltable>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <para>
   <example>
    <title>Displaying the Oracle error message after a connection error</title>
    <programlisting role="php">
<![CDATA[
<?php
$conn = oci_connect("hr", "welcome", "localhost/XE");
if (!$conn) {
    $e = oci_error();   // For oci_connect errors do not pass a handle
    trigger_error(htmlentities($e['message']), E_USER_ERROR);
}
?>
]]>
    </programlisting>
   </example>
  </para>
   <para>
   <example>
    <title>Displaying the Oracle error message after a parsing error</title>
    <programlisting role="php">
<![CDATA[
<?php
$stid = oci_parse($conn, "select ' from dual");  // note mismatched quote
if (!$stid) {
    $e = oci_error($conn);  // For oci_parse errors pass the connection handle
    trigger_error(htmlentities($e['message']), E_USER_ERROR);
}
?>
]]>
    </programlisting>
   </example>
  </para>
  <para>
   <example>
    <title>Displaying the Oracle error message, the problematic statement,
     and the position of the problem of an execution error</title>
    <programlisting role="php">
<![CDATA[
<?php
$stid = oci_parse($conn, "select does_not_exist from dual");
$r = oci_execute($stid);
if (!$r) {
    $e = oci_error($stid);  // For oci_execute errors pass the statement handle
    print htmlentities($e['message']);
    print "\n<pre>\n";
    print htmlentities($e['sqltext']);
    printf("\n%".($e['offset']+1)."s", "^");
    print  "\n</pre>\n";
}
?>
]]>
    </programlisting>
   </example>
  </para>
 </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
-->
