uTools-Manuals/docs/php/oci_error.html
2019-04-28 19:00:34 +08:00

79 lines
4.6 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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>返回上一个错误</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.oci-error" class="refentry">
<div class="refnamediv">
<h1 class="refname">oci_error</h1>
<p class="verinfo">(PHP 5, PHP 7, PECL OCI8 &gt;= 1.1.0)</p><p class="refpurpose"><span class="refname">oci_error</span> &mdash; <span class="dc-title">返回上一个错误</span></p>
</div>
<div class="refsect1 unknown-unknown-seealsq" id="refsect1-function.oci-error-unknown-unknown-seealsq">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>oci_error</strong></span>
([ <span class="methodparam"><span class="type">resource</span> <code class="parameter">$source</code></span>
] ) : <span class="type">array</span></div>
<p class="para rdfs-comment">
对于大多数错误,参数是最适合的资源句柄。对于
<span class="function"><a href="oci_connect.html" class="function">oci_connect()</a></span><span class="function"><a href="oci_new_connect.html" class="function">oci_new_connect()</a></span>
<span class="function"><a href="oci_pconnect.html" class="function">oci_pconnect()</a></span>
的连接错误,不要传递参数。如果没有发现错误,<span class="function"><strong>oci_error()</strong></span>
返回 <strong><code>FALSE</code></strong><span class="function"><strong>oci_error()</strong></span>
以一个关联数组返回错误。在此数组中,<em>code</em>
是 oracle 错误代码而 <em>message</em> 是 oracle 的错误字符串。
</p>
<blockquote class="note"><p><strong class="note">Note</strong>:
<strong>自 PHP 4.3 起</strong><br />
<p class="para">
<em>offset</em><em>sqltext</em>
也包括在返回的数组中,用来指出错误发生的位置以及造成错误的原始的 SQL 文本。
</p>
</p></blockquote>
<p class="para">
<div class="example" id="example-2406">
<p><strong>Example #1 连接错误后显示 Oracle 错误信息</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
$conn&nbsp;=&nbsp;@oci_connect("scott",&nbsp;"tiger",&nbsp;"mydb");<br />if&nbsp;(!$conn)&nbsp;{<br />&nbsp;&nbsp;$e&nbsp;=&nbsp;oci_error();&nbsp;&nbsp;&nbsp;//&nbsp;For&nbsp;oci_connect&nbsp;errors&nbsp;pass&nbsp;no&nbsp;handle<br />&nbsp;&nbsp;echo&nbsp;htmlentities($e['message']);<br />}</span>
</pre></div>
</div>
</div>
</p>
<p class="para">
<div class="example" id="example-2407">
<p><strong>Example #2 语法解析错误后显示 Oracle 错误信息</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
$stmt&nbsp;=&nbsp;@oci_parse($conn,&nbsp;"select&nbsp;'&nbsp;from&nbsp;dual");&nbsp;&nbsp;//&nbsp;note&nbsp;mismatched&nbsp;quote<br />if&nbsp;(!$stmt)&nbsp;{<br />&nbsp;&nbsp;$e&nbsp;=&nbsp;oci_error($conn);&nbsp;&nbsp;//&nbsp;For&nbsp;oci_parse&nbsp;errors&nbsp;pass&nbsp;the&nbsp;connection&nbsp;handle<br />&nbsp;&nbsp;echo&nbsp;htmlentities($e['message']);<br />}</span>
</pre></div>
</div>
</div>
</p>
<p class="para">
<div class="example" id="example-2408">
<p><strong>Example #3 执行错误后显示 Oracle 错误信息和出错的语句</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
$r&nbsp;=&nbsp;oci_execute($stmt);<br />if&nbsp;(!$r)&nbsp;{<br />&nbsp;&nbsp;$e&nbsp;=&nbsp;oci_error($stmt);&nbsp;//&nbsp;For&nbsp;oci_execute&nbsp;errors&nbsp;pass&nbsp;the&nbsp;statementhandle<br />&nbsp;&nbsp;echo&nbsp;htmlentities($e['message']);<br />&nbsp;&nbsp;echo&nbsp;"&lt;pre&gt;";<br />&nbsp;&nbsp;echo&nbsp;htmlentities($e['sqltext']);<br />&nbsp;&nbsp;printf("\n%".($e['offset']+1)."s",&nbsp;"^");<br />&nbsp;&nbsp;echo&nbsp;"&lt;/pre&gt;";<br />}</span>
</pre></div>
</div>
</div>
</p>
<blockquote class="note"><p><strong class="note">Note</strong>:
<p class="para">
在 PHP 5.0.0 之前的版本必须使用 <span class="function"><a href="ocierror.html" class="function">ocierror()</a></span>
替代本函数。该函数名仍然可用,为向下兼容作为
<span class="function"><strong>oci_error()</strong></span> 的别名。不过其已被废弃,不推荐使用。
</p>
</p></blockquote>
</div>
</div></div></div></body></html>