<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Returns the last error found</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.oci-define-by-name.html">oci_define_by_name</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.oci-execute.html">oci_execute</a></div> <div class="up"><a href="ref.oci8.html">OCI8 Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.oci-error" class="refentry"> <div class="refnamediv"> <h1 class="refname">oci_error</h1> <p class="verinfo">(PHP 5, PECL OCI8 >= 1.1.0)</p><p class="refpurpose"><span class="refname">oci_error</span> — <span class="dc-title">Returns the last error found</span></p> </div> <div class="refsect1 description" id="refsect1-function.oci-error-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">array</span> <span class="methodname"><strong>oci_error</strong></span> ([ <span class="methodparam"><span class="type">resource</span> <code class="parameter">$resource</code></span> ] )</div> <p class="para rdfs-comment"> Returns the last error found. </p> <p class="para"> The function should be called immediately after an error occurs. Errors are cleared by a successful statement. </p> </div> <div class="refsect1 parameters" id="refsect1-function.oci-error-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">resource</code></em></span> <dd> <p class="para"> For most errors, <em><code class="parameter">resource</code></em> is the resource handle that was passed to the failing function call. For connection errors with <span class="function"><a href="function.oci-connect.html" class="function">oci_connect()</a></span>, <span class="function"><a href="function.oci-new-connect.html" class="function">oci_new_connect()</a></span> or <span class="function"><a href="function.oci-pconnect.html" class="function">oci_pconnect()</a></span> do not pass <em><code class="parameter">resource</code></em>. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.oci-error-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> If no error is found, <span class="function"><strong>oci_error()</strong></span> returns <strong><code>FALSE</code></strong>. Otherwise, <span class="function"><strong>oci_error()</strong></span> returns the error information as an associative array. </p> <p class="para"> <table class="doctable table"> <caption><strong> <span class="function"><strong>oci_error()</strong></span> Array Description</strong></caption> <thead> <tr> <th>Array key</th> <th>Type</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td><em>code</em></td> <td><span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span></td> <td> The Oracle error number. </td> </tr> <tr> <td><em>message</em></td> <td><span class="type"><a href="language.types.string.html" class="type string">string</a></span></td> <td> The Oracle error text. </td> </tr> <tr> <td><em>offset</em></td> <td><span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span></td> <td> The byte position of an error in the SQL statement. If there was no statement, this is <em>0</em> </td> </tr> <tr> <td><em>sqltext</em></td> <td><span class="type"><a href="language.types.string.html" class="type string">string</a></span></td> <td> The SQL statement text. If there was no statement, this is an empty string. </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 changelog" id="refsect1-function.oci-error-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>4.3.0</td> <td> The <em>offset</em> and <em>sqltext</em> entries were added. </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 examples" id="refsect1-function.oci-error-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-1970"> <p><strong>Example #1 Displaying the Oracle error message after a connection error</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$conn </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"hr"</span><span style="color: #007700">, </span><span style="color: #DD0000">"welcome"</span><span style="color: #007700">, </span><span style="color: #DD0000">"localhost/XE"</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$conn</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">$e </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_error</span><span style="color: #007700">(); </span><span style="color: #FF8000">// For oci_connect errors do not pass a handle<br /> </span><span style="color: #0000BB">trigger_error</span><span style="color: #007700">(</span><span style="color: #0000BB">htmlentities</span><span style="color: #007700">(</span><span style="color: #0000BB">$e</span><span style="color: #007700">[</span><span style="color: #DD0000">'message'</span><span style="color: #007700">]), </span><span style="color: #0000BB">E_USER_ERROR</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> <p class="para"> <div class="example" id="example-1971"> <p><strong>Example #2 Displaying the Oracle error message after a parsing error</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$stid </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_parse</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">, </span><span style="color: #DD0000">"select ' from dual"</span><span style="color: #007700">); </span><span style="color: #FF8000">// note mismatched quote<br /></span><span style="color: #007700">if (!</span><span style="color: #0000BB">$stid</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">$e </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_error</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">); </span><span style="color: #FF8000">// For oci_parse errors pass the connection handle<br /> </span><span style="color: #0000BB">trigger_error</span><span style="color: #007700">(</span><span style="color: #0000BB">htmlentities</span><span style="color: #007700">(</span><span style="color: #0000BB">$e</span><span style="color: #007700">[</span><span style="color: #DD0000">'message'</span><span style="color: #007700">]), </span><span style="color: #0000BB">E_USER_ERROR</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> <p class="para"> <div class="example" id="example-1972"> <p><strong>Example #3 Displaying the Oracle error message, the problematic statement, and the position of the problem of an execution error</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$stid </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_parse</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">, </span><span style="color: #DD0000">"select does_not_exist from dual"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$r </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$r</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">$e </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_error</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">); </span><span style="color: #FF8000">// For oci_execute errors pass the statement handle<br /> </span><span style="color: #007700">print </span><span style="color: #0000BB">htmlentities</span><span style="color: #007700">(</span><span style="color: #0000BB">$e</span><span style="color: #007700">[</span><span style="color: #DD0000">'message'</span><span style="color: #007700">]);<br /> print </span><span style="color: #DD0000">"\n<pre>\n"</span><span style="color: #007700">;<br /> print </span><span style="color: #0000BB">htmlentities</span><span style="color: #007700">(</span><span style="color: #0000BB">$e</span><span style="color: #007700">[</span><span style="color: #DD0000">'sqltext'</span><span style="color: #007700">]);<br /> </span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"\n%"</span><span style="color: #007700">.(</span><span style="color: #0000BB">$e</span><span style="color: #007700">[</span><span style="color: #DD0000">'offset'</span><span style="color: #007700">]+</span><span style="color: #0000BB">1</span><span style="color: #007700">).</span><span style="color: #DD0000">"s"</span><span style="color: #007700">, </span><span style="color: #DD0000">"^"</span><span style="color: #007700">);<br /> print </span><span style="color: #DD0000">"\n</pre>\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.oci-define-by-name.html">oci_define_by_name</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.oci-execute.html">oci_execute</a></div> <div class="up"><a href="ref.oci8.html">OCI8 Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>