uTools-Manuals/docs/php/pg_result_error_field.html
2019-04-08 23:22:26 +08:00

119 lines
6.7 KiB
HTML

<!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 an individual field of an error report</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.pg-result-error-field" class="refentry">
<div class="refnamediv">
<h1 class="refname">pg_result_error_field</h1>
<p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7)</p><p class="refpurpose"><span class="refname">pg_result_error_field</span> &mdash; <span class="dc-title">Returns an individual field of an error report</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.pg-result-error-field-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>pg_result_error_field</strong></span>
( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$result</code></span>
, <span class="methodparam"><span class="type">int</span> <code class="parameter">$fieldcode</code></span>
) : <span class="type">string</span></div>
<p class="para rdfs-comment">
<span class="function"><strong>pg_result_error_field()</strong></span> returns one of the detailed error message
fields associated with <code class="parameter">result</code> resource. It is only available
against a PostgreSQL 7.4 or above server. The error field is specified by
the <code class="parameter">fieldcode</code>.
</p>
<p class="para">
Because <span class="function"><a href="pg_query.html" class="function">pg_query()</a></span> and <span class="function"><a href="pg_query_params.html" class="function">pg_query_params()</a></span> return <strong><code>FALSE</code></strong> if the query fails,
you must use <span class="function"><a href="pg_send_query.html" class="function">pg_send_query()</a></span> and
<span class="function"><a href="pg_get_result.html" class="function">pg_get_result()</a></span> to get the result handle.
</p>
<p class="para">
If you need to get additional error information from failed <span class="function"><a href="pg_query.html" class="function">pg_query()</a></span> queries,
use <span class="function"><a href="pg_set_error_verbosity.html" class="function">pg_set_error_verbosity()</a></span> and <span class="function"><a href="pg_last_error.html" class="function">pg_last_error()</a></span>
and then parse the result.
</p>
</div>
<div class="refsect1 parameters" id="refsect1-function.pg-result-error-field-parameters">
<h3 class="title">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">result</code></dt>
<dd>
<p class="para">
A PostgreSQL query result resource from a previously executed
statement.
</p>
</dd>
<dt>
<code class="parameter">fieldcode</code></dt>
<dd>
<p class="para">
Possible <code class="parameter">fieldcode</code> values are: <strong><code>PGSQL_DIAG_SEVERITY</code></strong>,
<strong><code>PGSQL_DIAG_SQLSTATE</code></strong>, <strong><code>PGSQL_DIAG_MESSAGE_PRIMARY</code></strong>,
<strong><code>PGSQL_DIAG_MESSAGE_DETAIL</code></strong>,
<strong><code>PGSQL_DIAG_MESSAGE_HINT</code></strong>, <strong><code>PGSQL_DIAG_STATEMENT_POSITION</code></strong>,
<strong><code>PGSQL_DIAG_INTERNAL_POSITION</code></strong> (PostgreSQL 8.0+ only),
<strong><code>PGSQL_DIAG_INTERNAL_QUERY</code></strong> (PostgreSQL 8.0+ only),
<strong><code>PGSQL_DIAG_CONTEXT</code></strong>, <strong><code>PGSQL_DIAG_SOURCE_FILE</code></strong>,
<strong><code>PGSQL_DIAG_SOURCE_LINE</code></strong> or
<strong><code>PGSQL_DIAG_SOURCE_FUNCTION</code></strong>.
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.pg-result-error-field-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">A <span class="type"><a href="language.types.string.html" class="type string">string</a></span> containing the contents of the error field, <strong><code>NULL</code></strong> if the field does not exist or <strong><code>FALSE</code></strong>
on failure.</p>
</div>
<div class="refsect1 examples" id="refsect1-function.pg-result-error-field-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-2513">
<p><strong>Example #1 <span class="function"><strong>pg_result_error_field()</strong></span> example</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;$dbconn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"dbname=publisher"</span><span style="color: #007700">)&nbsp;or&nbsp;die(</span><span style="color: #DD0000">"Could&nbsp;not&nbsp;connect"</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;if&nbsp;(!</span><span style="color: #0000BB">pg_connection_busy</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbconn</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">pg_send_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbconn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"select&nbsp;*&nbsp;from&nbsp;doesnotexist;"</span><span style="color: #007700">);<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$res1&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_get_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbconn</span><span style="color: #007700">);<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">pg_result_error_field</span><span style="color: #007700">(</span><span style="color: #0000BB">$res1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PGSQL_DIAG_SQLSTATE</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
</div>
</p>
</div>
<div class="refsect1 seealso" id="refsect1-function.pg-result-error-field-seealso">
<h3 class="title">参见</h3>
<p class="para">
<ul class="simplelist">
<li class="member"><span class="function"><a href="pg_result_error.html" class="function" rel="rdfs-seeAlso">pg_result_error()</a> - 获得查询结果的错误信息</span></li>
</ul>
</p>
</div>
</div></div></div></body></html>