<!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><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.pg-query.html">pg_query</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pg-result-error.html">pg_result_error</a></div> <div class="up"><a href="ref.pgsql.html">PostgreSQL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><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 >= 5.1.0)</p><p class="refpurpose"><span class="refname">pg_result_error_field</span> — <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">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">string</span> <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> )</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 <em><code class="parameter">result</code></em> resource. It is only available against a PostgreSQL 7.4 or above server. The error field is specified by the <em><code class="parameter">fieldcode</code></em>. </p> <p class="para"> Because <span class="function"><a href="function.pg-query.html" class="function">pg_query()</a></span> and <span class="function"><a href="function.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="function.pg-send-query.html" class="function">pg_send_query()</a></span> and <span class="function"><a href="function.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="function.pg-query.html" class="function">pg_query()</a></span> queries, use <span class="function"><a href="function.pg-set-error-verbosity.html" class="function">pg_set_error_verbosity()</a></span> and <span class="function"><a href="function.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">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">result</code></em></span> <dd> <p class="para"> A PostgreSQL query result resource from a previously executed statement. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">fieldcode</code></em></span> <dd> <p class="para"> Possible <em><code class="parameter">fieldcode</code></em> 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> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.pg-result-error-field-returnvalues"> <h3 class="title">Return Values</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">Examples</h3> <p class="para"> <div class="example" id="example-2112"> <p><strong>Example #1 <span class="function"><strong>pg_result_error_field()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /> $dbconn </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"dbname=publisher"</span><span style="color: #007700">) or die(</span><span style="color: #DD0000">"Could not connect"</span><span style="color: #007700">);<br /><br /> if (!</span><span style="color: #0000BB">pg_connection_busy</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbconn</span><span style="color: #007700">)) {<br /> </span><span style="color: #0000BB">pg_send_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbconn</span><span style="color: #007700">, </span><span style="color: #DD0000">"select * from doesnotexist;"</span><span style="color: #007700">);<br /> }<br /> <br /> </span><span style="color: #0000BB">$res1 </span><span style="color: #007700">= </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 /> echo </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">, </span><span style="color: #0000BB">PGSQL_DIAG_SQLSTATE</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.pg-result-error-field-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.pg-result-error.html" class="function" rel="rdfs-seeAlso">pg_result_error()</a> - Get error message associated with result</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.pg-query.html">pg_query</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pg-result-error.html">pg_result_error</a></div> <div class="up"><a href="ref.pgsql.html">PostgreSQL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>