?? function.db2-fetch-both.html
字號(hào):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Returns an array, indexed by both column name and position, representing a row in a result set</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.db2-fetch-assoc.html">db2_fetch_assoc</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.db2-fetch-object.html">db2_fetch_object</a></div> <div class="up"><a href="ref.ibm-db2.html">IBM DB2 Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.db2-fetch-both" class="refentry"> <div class="refnamediv"> <h1 class="refname">db2_fetch_both</h1> <p class="verinfo">(PECL ibm_db2:1.0-1.6.2)</p><p class="refpurpose"><span class="refname">db2_fetch_both</span> — <span class="dc-title"> Returns an array, indexed by both column name and position, representing a row in a result set </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>db2_fetch_both</b></b></span> ( <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$stmt</tt></span> [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$row_number</tt></span> ] )</div> <p class="para rdfs-comment"> Returns an array, indexed by both column name and position, representing a row in a result set. Note that the row returned by <b>db2_fetch_both()</b> requires more memory than the single-indexed arrays returned by <a href="function.db2-fetch-assoc.html" class="function">db2_fetch_assoc()</a> or <a href="function.db2-fetch-array.html" class="function">db2_fetch_array()</a>. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">stmt</tt></i></span> <dd> <p class="para"> A valid <i>stmt</i> resource containing a result set. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">row_number</tt></i></span> <dd> <p class="para"> Requests a specific 1-indexed row from the result set. Passing this parameter results in a PHP warning if the result set uses a forward-only cursor. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns an associative array with column values indexed by both the column name and 0-indexed column number. The array represents the next or requested row in the result set. Returns <b><tt>FALSE</tt></b> if there are no rows left in the result set, or if the row requested by <i><tt class="parameter">row_number</tt></i> does not exist in the result set. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 Iterating through a forward-only cursor</b></p> <div class="example-contents"><p> If you call <b>db2_fetch_both()</b> without a specific row number, it automatically retrieves the next row in the result set. The following example accesses columns in the returned array by both column name and by numeric index. </p></div> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /><br />$sql </span><span style="color: #007700">= </span><span style="color: #DD0000">"SELECT id, name, breed, weight FROM animals ORDER BY breed"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$stmt </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">, </span><span style="color: #0000BB">$sql</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">);<br /><br />while (</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_fetch_both</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">)) {<br /> </span><span style="color: #0000BB">printf </span><span style="color: #007700">(</span><span style="color: #DD0000">"%-5d %-16s %-32s %10s\n"</span><span style="color: #007700">, <br /> </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'ID'</span><span style="color: #007700">], </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">], </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'BREED'</span><span style="color: #007700">], </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">3</span><span style="color: #007700">]);<br />}<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"><pre><div class="cdata"><pre>0 Pook cat 3.205 Rickety Ride goat 9.702 Smarty horse 350.00</pre></div> </pre></div> </div> <div class="example"> <p><b>Example #2 Retrieving specific rows with <b>db2_fetch_both()</b> from a scrollable cursor</b></p> <div class="example-contents"><p> If your result set uses a scrollable cursor, you can call <b>db2_fetch_both()</b> with a specific row number. The following example retrieves every other row in the result set, starting with the second row. </p></div> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /><br />$sql </span><span style="color: #007700">= </span><span style="color: #DD0000">"SELECT id, name, breed, weight FROM animals ORDER BY breed"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">, </span><span style="color: #0000BB">$sql</span><span style="color: #007700">, array(</span><span style="color: #DD0000">'cursor' </span><span style="color: #007700">=> </span><span style="color: #0000BB">DB2_SCROLLABLE</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">$i</span><span style="color: #007700">=</span><span style="color: #0000BB">2</span><span style="color: #007700">;<br />while (</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_fetch_both</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">, </span><span style="color: #0000BB">$i</span><span style="color: #007700">)) {<br /> </span><span style="color: #0000BB">printf </span><span style="color: #007700">(</span><span style="color: #DD0000">"%-5d %-16s %-32s %10s\n"</span><span style="color: #007700">, <br /> </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">], </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'NAME'</span><span style="color: #007700">], </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">2</span><span style="color: #007700">], </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'WEIGHT'</span><span style="color: #007700">]);<br /> </span><span style="color: #0000BB">$i </span><span style="color: #007700">= </span><span style="color: #0000BB">$i </span><span style="color: #007700">+ </span><span style="color: #0000BB">2</span><span style="color: #007700">;<br />}<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"><pre><div class="cdata"><pre>0 Pook cat 3.205 Rickety Ride goat 9.702 Smarty horse 350.00</pre></div> </pre></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.db2-fetch-array.html" class="function" rel="rdfs-seeAlso">db2_fetch_array()</a></li> <li class="member"><a href="function.db2-fetch-assoc.html" class="function" rel="rdfs-seeAlso">db2_fetch_assoc()</a></li> <li class="member"><a href="function.db2-fetch-object.html" class="function" rel="rdfs-seeAlso">db2_fetch_object()</a></li> <li class="member"><a href="function.db2-fetch-row.html" class="function" rel="rdfs-seeAlso">db2_fetch_row()</a></li> <li class="member"><a href="function.db2-result.html" class="function" rel="rdfs-seeAlso">db2_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.db2-fetch-assoc.html">db2_fetch_assoc</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.db2-fetch-object.html">db2_fetch_object</a></div> <div class="up"><a href="ref.ibm-db2.html">IBM DB2 Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -