⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 function.pg-fetch-assoc.html

📁 php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Fetch a row as an associative array</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.pg-fetch-array.html">pg_fetch_array</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pg-fetch-object.html">pg_fetch_object</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-assoc" class="refentry"> <div class="refnamediv">  <h1 class="refname">pg_fetch_assoc</h1>  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5)</p><p class="refpurpose"><span class="refname">pg_fetch_assoc</span> &mdash; <span class="dc-title">Fetch a row as an associative array</span></p> </div> <div class="refsect1 description">  <h3 class="title">Description</h3>  <div class="methodsynopsis dc-description">   <span class="type">array</span> <span class="methodname"><b><b>pg_fetch_assoc</b></b></span>    ( <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$result</tt></span>   [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$row</tt></span>  ] )</div>  <p class="para rdfs-comment">   <b>pg_fetch_assoc()</b> returns an associative array that   corresponds to the fetched row (records).  </p>  <p class="para">   <b>pg_fetch_assoc()</b> is equivalent to calling   <a href="function.pg-fetch-array.html" class="function">pg_fetch_array()</a> with <b><tt>PGSQL_ASSOC</tt></b> as the   optional third parameter. It only returns an associative array.   If you need the numeric indices, use    <a href="function.pg-fetch-row.html" class="function">pg_fetch_row()</a>.    </p>  <blockquote><p><b class="note">Note</b>: <span class="simpara">This function sets NULL fields tothe PHP <b><tt>NULL</tt></b> value.</span></p></blockquote>  <p class="para">   <b>pg_fetch_assoc()</b> is NOT significantly   slower than using <a href="function.pg-fetch-row.html" class="function">pg_fetch_row()</a>, and   is significantly easier to use.  </p> </div> <div class="refsect1 parameters">  <h3 class="title">Parameters</h3>  <p class="para">   <dl>    <dt>     <span class="term"><i><tt class="parameter">result</tt></i></span>     <dd>      <p class="para">       PostgreSQL query result resource, returned by <a href="function.pg-query.html" class="function">pg_query()</a>,       <a href="function.pg-query-params.html" class="function">pg_query_params()</a> or <a href="function.pg-execute.html" class="function">pg_execute()</a>       (among others).      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">row</tt></i></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>   </dl>  </p> </div> <div class="refsect1 returnvalues">  <h3 class="title">Return Values</h3>  <p class="para">   An <a href="language.types.array.html" class="type array">array</a> indexed associatively (by field name).   Each value in the <a href="language.types.array.html" class="type array">array</a> is represented as a    <a href="language.types.string.html" class="type string">string</a>.  Database <i>NULL</i>   values are returned as <b><tt>NULL</tt></b>.  </p>  <p class="para">   <b><tt>FALSE</tt></b> is returned if <i><tt class="parameter">row</tt></i> exceeds the number   of rows in the set, there are no more rows, or on any other error.  </p> </div> <div class="refsect1 changelog">  <h3 class="title">ChangeLog</h3>  <p class="para">   <table class="informaltable">    <colgroup>     <thead valign="middle">      <tr valign="middle">       <th colspan="1">Version</th>       <th colspan="1">Description</th>      </tr>     </thead>     <tbody valign="middle" class="tbody">      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">4.1.0</td>       <td colspan="1" rowspan="1" align="left">        The parameter <i><tt class="parameter">row</tt></i> became optional.       </td>      </tr>     </tbody>    </colgroup>   </table>  </p> </div> <div class="refsect1 examples">  <h3 class="title">Examples</h3>  <p class="para">   <div class="example">    <p><b>Example #1 <b>pg_fetch_assoc()</b> example</b></p>    <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php&nbsp;<br />$conn&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">);<br />if&nbsp;(!</span><span style="color: #0000BB">$conn</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"An&nbsp;error&nbsp;occured.\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;exit;<br />}<br /><br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;id,&nbsp;author,&nbsp;email&nbsp;FROM&nbsp;authors"</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$result</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"An&nbsp;error&nbsp;occured.\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;exit;<br />}<br /><br />while&nbsp;(</span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_fetch_assoc</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'id'</span><span style="color: #007700">];<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'author'</span><span style="color: #007700">];<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'email'</span><span style="color: #007700">];<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </div>   </div>  </p> </div> <div class="refsect1 seealso">  <h3 class="title">See Also</h3>  <p class="para">   <ul class="simplelist">    <li class="member"><a href="function.pg-fetch-row.html" class="function" rel="rdfs-seeAlso">pg_fetch_row()</a></li>    <li class="member"><a href="function.pg-fetch-array.html" class="function" rel="rdfs-seeAlso">pg_fetch_array()</a></li>    <li class="member"><a href="function.pg-fetch-object.html" class="function" rel="rdfs-seeAlso">pg_fetch_object()</a></li>    <li class="member"><a href="function.pg-fetch-result.html" class="function" rel="rdfs-seeAlso">pg_fetch_result()</a></li>   </ul>  </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.pg-fetch-array.html">pg_fetch_array</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pg-fetch-object.html">pg_fetch_object</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>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -