php-doc-en/reference/oci8/functions/oci-error.xml
Maciej Sobaczewski 8b5940cade Remove changelogs for PHP 4 - 2nd round
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@334605 c90b9560-bf6c-de11-be94-00142212c4b1
2014-08-26 14:28:17 +00:00

178 lines
4.6 KiB
XML

<?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>array</type><methodname>oci_error</methodname>
<methodparam choice="opt"><type>resource</type><parameter>resource</parameter></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>resource</parameter></term>
<listitem>
<para>
For most errors, <parameter>resource</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> do not pass <parameter>resource</parameter>.
</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>integer</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>integer</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="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
-->