<!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 values from a result resource</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.pg-fetch-object.html">pg_fetch_object</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pg-fetch-row.html">pg_fetch_row</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-fetch-result" class="refentry"> <div class="refnamediv"> <h1 class="refname">pg_fetch_result</h1> <p class="verinfo">(PHP 4 >= 4.2.0, PHP 5)</p><p class="refpurpose"><span class="refname">pg_fetch_result</span> — <span class="dc-title">Returns values from a result resource</span></p> </div> <div class="refsect1 description" id="refsect1-function.pg-fetch-result-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">string</span> <span class="methodname"><strong>pg_fetch_result</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">$row</code></span> , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$field</code></span> )</div> <div class="methodsynopsis dc-description"> <span class="type">string</span> <span class="methodname"><strong>pg_fetch_result</strong></span> ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$result</code></span> , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$field</code></span> )</div> <p class="para rdfs-comment"> <span class="function"><strong>pg_fetch_result()</strong></span> returns the value of a particular row and field (column) in a PostgreSQL result resource. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> This function used to be called <span class="function"><strong>pg_result()</strong></span>. </p> </p></blockquote> </div> <div class="refsect1 parameters" id="refsect1-function.pg-fetch-result-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"> PostgreSQL query result resource, returned by <span class="function"><a href="function.pg-query.html" class="function">pg_query()</a></span>, <span class="function"><a href="function.pg-query-params.html" class="function">pg_query_params()</a></span> or <span class="function"><a href="function.pg-execute.html" class="function">pg_execute()</a></span> (among others). </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">row</code></em></span> <dd> <p class="para"> Row number in result to fetch. Rows are numbered from 0 upwards. If omitted, next row is fetched. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">field</code></em></span> <dd> <p class="para"> A <span class="type"><a href="language.types.string.html" class="type string">string</a></span> representing the name of the field (column) to fetch, otherwise an <span class="type"><a href="language.types.integer.html" class="type int">int</a></span> representing the field number to fetch. Fields are numbered from 0 upwards. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.pg-fetch-result-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Boolean is returned as "t" or "f". All other types, including arrays are returned as strings formatted in the same default PostgreSQL manner that you would see in the <strong class="command">psql</strong> program. Database <em>NULL</em> values are returned as <strong><code>NULL</code></strong>. </p> <p class="para"> <strong><code>FALSE</code></strong> is returned if <em><code class="parameter">row</code></em> exceeds the number of rows in the set, or on any other error. </p> </div> <div class="refsect1 examples" id="refsect1-function.pg-fetch-result-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2069"> <p><strong>Example #1 <span class="function"><strong>pg_fetch_result()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$db </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"dbname=users user=me"</span><span style="color: #007700">) || die();<br /><br /></span><span style="color: #0000BB">$res </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">, </span><span style="color: #DD0000">"SELECT 1 UNION ALL SELECT 2"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$val </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_fetch_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #DD0000">"First field in the second row is: "</span><span style="color: #007700">, </span><span style="color: #0000BB">$val</span><span style="color: #007700">, </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> First field in the second row is: 2 </pre></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.pg-fetch-result-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.pg-query.html" class="function" rel="rdfs-seeAlso">pg_query()</a> - Execute a query</span></li> <li class="member"> <span class="function"><a href="function.pg-fetch-array.html" class="function" rel="rdfs-seeAlso">pg_fetch_array()</a> - Fetch a row as an array</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-fetch-object.html">pg_fetch_object</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pg-fetch-row.html">pg_fetch_row</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>