uTools-Manuals/docs/php/db2_fetch_row.html
2019-04-08 23:22:26 +08:00

166 lines
15 KiB
HTML

<!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>Sets the result set pointer to the next row or requested row</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.db2-fetch-row" class="refentry">
<div class="refnamediv">
<h1 class="refname">db2_fetch_row</h1>
<p class="verinfo">(PECL ibm_db2 &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">db2_fetch_row</span> &mdash; <span class="dc-title">
Sets the result set pointer to the next row or requested row
</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.db2-fetch-row-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>db2_fetch_row</strong></span>
( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$stmt</code></span>
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$row_number</code></span>
] ) : <span class="type">bool</span></div>
<p class="para rdfs-comment">
Use <span class="function"><strong>db2_fetch_row()</strong></span> to iterate through a result set, or
to point to a specific row in a result set if you requested a scrollable
cursor.
</p>
<p class="para">
To retrieve individual fields from the result set, call the
<span class="function"><a href="db2_result.html" class="function">db2_result()</a></span> function.
</p>
<p class="para">
Rather than calling <span class="function"><strong>db2_fetch_row()</strong></span> and
<span class="function"><a href="db2_result.html" class="function">db2_result()</a></span>, most applications will call one of
<span class="function"><a href="db2_fetch_assoc.html" class="function">db2_fetch_assoc()</a></span>, <span class="function"><a href="db2_fetch_both.html" class="function">db2_fetch_both()</a></span>,
or <span class="function"><a href="db2_fetch_array.html" class="function">db2_fetch_array()</a></span> to advance the result set pointer
and return a complete row as an array.
</p>
</div>
<div class="refsect1 parameters" id="refsect1-function.db2-fetch-row-parameters">
<h3 class="title">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">stmt</code></dt>
<dd>
<p class="para">
A valid <em>stmt</em> resource.
</p>
</dd>
<dt>
<code class="parameter">row_number</code></dt>
<dd>
<p class="para">
With scrollable cursors, you can request a specific row number in the
result set. Row numbering is 1-indexed.
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.db2-fetch-row-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
Returns <strong><code>TRUE</code></strong> if the requested row exists in the result set. Returns
<strong><code>FALSE</code></strong> if the requested row does not exist in the result set.
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.db2-fetch-row-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-1260">
<p><strong>Example #1 Iterating through a result set</strong></p>
<div class="example-contents"><p>
The following example demonstrates how to iterate through a result set
with <span class="function"><strong>db2_fetch_row()</strong></span> and retrieve columns from the
result set with <span class="function"><a href="db2_result.html" class="function">db2_result()</a></span>.
</p></div>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$sql&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'SELECT&nbsp;name,&nbsp;breed&nbsp;FROM&nbsp;animals&nbsp;WHERE&nbsp;weight&nbsp;&lt;&nbsp;?'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sql</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">db2_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #0000BB">10</span><span style="color: #007700">));<br />while&nbsp;(</span><span style="color: #0000BB">db2_fetch_row</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$name&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$breed&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$name</span><span style="color: #DD0000">&nbsp;</span><span style="color: #0000BB">$breed</span><span style="color: #DD0000">"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
<div class="example-contents"><p>以上例程会输出:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
cat Pook
gold fish Bubbles
budgerigar Gizmo
goat Rickety Ride
</pre></div>
</div>
</div>
<div class="example" id="example-1261">
<p><strong>Example #2 i5/OS recommended alternatives to db2_fetch_row/db2_result</strong></p>
<div class="example-contents"><p>
On i5/OS it is recommended that you use <span class="function"><a href="db2_fetch_both.html" class="function">db2_fetch_both()</a></span>,
<span class="function"><a href="db2_fetch_array.html" class="function">db2_fetch_array()</a></span>, or <span class="function"><a href="db2_fetch_object.html" class="function">db2_fetch_object()</a></span>
over <span class="function"><strong>db2_fetch_row()</strong></span>/<span class="function"><a href="db2_result.html" class="function">db2_result()</a></span>. In general
<span class="function"><strong>db2_fetch_row()</strong></span>/<span class="function"><a href="db2_result.html" class="function">db2_result()</a></span> have more issues
with various column types in <em>EBCIDIC</em> to <em>ASCII</em>
translation, including possible truncation in <em>DBCS</em> applications.
You may also find the performance of <span class="function"><a href="db2_fetch_both.html" class="function">db2_fetch_both()</a></span>,
<span class="function"><a href="db2_fetch_array.html" class="function">db2_fetch_array()</a></span>, and <span class="function"><a href="db2_fetch_object.html" class="function">db2_fetch_object()</a></span> to
be superior to <span class="function"><strong>db2_fetch_row()</strong></span>/<span class="function"><a href="db2_result.html" class="function">db2_result()</a></span>.
</p></div>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">""</span><span style="color: #007700">,</span><span style="color: #DD0000">""</span><span style="color: #007700">,</span><span style="color: #DD0000">""</span><span style="color: #007700">);<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$sql&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'SELECT&nbsp;SPECIFIC_SCHEMA,&nbsp;SPECIFIC_NAME,&nbsp;ROUTINE_SCHEMA,&nbsp;ROUTINE_NAME,&nbsp;ROUTINE_TYPE,&nbsp;ROUTINE_CREATED,&nbsp;ROUTINE_BODY,&nbsp;IN_PARMS,&nbsp;OUT_PARMS,&nbsp;INOUT_PARMS,&nbsp;PARAMETER_STYLE,&nbsp;EXTERNAL_NAME,&nbsp;EXTERNAL_LANGUAGE&nbsp;FROM&nbsp;QSYS2.SYSROUTINES&nbsp;FETCH&nbsp;FIRST&nbsp;2&nbsp;ROWS&nbsp;ONLY'</span><span style="color: #007700">;<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sql</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">'cursor'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_SCROLLABLE</span><span style="color: #007700">));<br />&nbsp;&nbsp;while&nbsp;(</span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</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 />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"&lt;br&gt;db2_fetch_both&nbsp;</span><span style="color: #007700">{</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'SPECIFIC_NAME'</span><span style="color: #007700">]}</span><span style="color: #DD0000">&nbsp;</span><span style="color: #007700">{</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'ROUTINE_CREATED'</span><span style="color: #007700">]}</span><span style="color: #DD0000">&nbsp;</span><span style="color: #007700">{</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">5</span><span style="color: #007700">]}</span><span style="color: #DD0000">"</span><span style="color: #007700">;<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sql</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">'cursor'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_SCROLLABLE</span><span style="color: #007700">));<br />&nbsp;&nbsp;while&nbsp;(</span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_fetch_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">)){<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"&lt;br&gt;db2_fetch_array&nbsp;</span><span style="color: #007700">{</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]}</span><span style="color: #DD0000">&nbsp;&nbsp;</span><span style="color: #007700">{</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">5</span><span style="color: #007700">]}</span><span style="color: #DD0000">"</span><span style="color: #007700">;<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sql</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">'cursor'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_SCROLLABLE</span><span style="color: #007700">));<br />&nbsp;&nbsp;while&nbsp;(</span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_fetch_object</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">)){<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"&lt;br&gt;db2_fetch_object&nbsp;</span><span style="color: #007700">{</span><span style="color: #0000BB">$row</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">SPECIFIC_NAME</span><span style="color: #007700">}</span><span style="color: #DD0000">&nbsp;</span><span style="color: #007700">{</span><span style="color: #0000BB">$row</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">ROUTINE_CREATED</span><span style="color: #007700">}</span><span style="color: #DD0000">"</span><span style="color: #007700">;<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;</span><span style="color: #0000BB">db2_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
<div class="example-contents"><p>以上例程会输出:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
db2_fetch_both MATCH_ANIMAL 2006-08-25-17.10.23.775000 2006-08-25-17.10.23.775000
db2_fetch_both MULTIRESULTS 2006-10-17-10.11.05.308000 2006-10-17-10.11.05.308000
db2_fetch_array MATCH_ANIMAL 2006-08-25-17.10.23.775000
db2_fetch_array MULTIRESULTS 2006-10-17-10.11.05.308000
db2_fetch_object MATCH_ANIMAL 2006-08-25-17.10.23.775000
db2_fetch_object MULTIRESULTS 2006-10-17-10.11.05.308000
</pre></div>
</div>
</div>
</p>
</div>
<div class="refsect1 seealso" id="refsect1-function.db2-fetch-row-seealso">
<h3 class="title">参见</h3>
<p class="para">
<ul class="simplelist">
<li class="member"><span class="function"><a href="db2_fetch_array.html" class="function" rel="rdfs-seeAlso">db2_fetch_array()</a> - Returns an array, indexed by column position, representing a row in a result set</span></li>
<li class="member"><span class="function"><a href="db2_fetch_assoc.html" class="function" rel="rdfs-seeAlso">db2_fetch_assoc()</a> - Returns an array, indexed by column name, representing a row in a result set</span></li>
<li class="member"><span class="function"><a href="db2_fetch_both.html" class="function" rel="rdfs-seeAlso">db2_fetch_both()</a> - Returns an array, indexed by both column name and position, representing a row in a result set</span></li>
<li class="member"><span class="function"><a href="db2_fetch_object.html" class="function" rel="rdfs-seeAlso">db2_fetch_object()</a> - Returns an object with properties representing columns in the fetched row</span></li>
<li class="member"><span class="function"><a href="db2_result.html" class="function" rel="rdfs-seeAlso">db2_result()</a> - Returns a single column from a row in the result set</span></li>
</ul>
</p>
</div>
</div></div></div></body></html>