<!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 field number of the named field</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.pg-field-name.html">pg_field_name</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pg-field-prtlen.html">pg_field_prtlen</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-field-num" class="refentry"> <div class="refnamediv"> <h1 class="refname">pg_field_num</h1> <p class="verinfo">(PHP 4 >= 4.2.0, PHP 5)</p><p class="refpurpose"><span class="refname">pg_field_num</span> — <span class="dc-title">Returns the field number of the named field</span></p> </div> <div class="refsect1 description" id="refsect1-function.pg-field-num-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">int</span> <span class="methodname"><strong>pg_field_num</strong></span> ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$result</code></span> , <span class="methodparam"><span class="type">string</span> <code class="parameter">$field_name</code></span> )</div> <p class="para rdfs-comment"> <span class="function"><strong>pg_field_num()</strong></span> will return the number of the field number that corresponds to the <em><code class="parameter">field_name</code></em> in the given PostgreSQL <em><code class="parameter">result</code></em> 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_fieldnum()</strong></span>. </p> </p></blockquote> </div> <div class="refsect1 parameters" id="refsect1-function.pg-field-num-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">field_name</code></em></span> <dd> <p class="para"> The name of the field. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.pg-field-num-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> The field number (numbered from 0), or -1 on error. </p> </div> <div class="refsect1 examples" id="refsect1-function.pg-field-num-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2073"> <p><strong>Example #1 Getting information about fields</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 /> </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">$dbconn</span><span style="color: #007700">, </span><span style="color: #DD0000">"select author, year, title from authors where author = 'Orwell'"</span><span style="color: #007700">);<br /> <br /> echo </span><span style="color: #DD0000">"Column 'title' is field number: "</span><span style="color: #007700">, </span><span style="color: #0000BB">pg_field_num</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">, </span><span style="color: #DD0000">'title'</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> Column 'title' is field number: 2 </pre></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.pg-field-num-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.pg-field-name.html" class="function" rel="rdfs-seeAlso">pg_field_name()</a> - Returns the name of a field</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-field-name.html">pg_field_name</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pg-field-prtlen.html">pg_field_prtlen</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>