Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > 05cd670d8a02b2b4a0ffb1756f2e8308 > files > 5816

php-manual-zh-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>db2_fetch_row</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="PHP 手册"
HREF="index.html"><LINK
REL="UP"
TITLE="IBM DB2, Cloudscape and Apache Derby Functions"
HREF="ref.ibm-db2.html"><LINK
REL="PREVIOUS"
TITLE="db2_fetch_object"
HREF="function.db2-fetch-object.html"><LINK
REL="NEXT"
TITLE="db2_field_display_size"
HREF="function.db2-field-display-size.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP 手册</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.db2-fetch-object.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.db2-field-display-size.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.db2-fetch-row"
></A
>db2_fetch_row</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN80986"
></A
><P
>    (PECL)</P
>db2_fetch_row&nbsp;--&nbsp;
   Sets the result set pointer to the next row or requested row
  </DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN80989"
></A
><H2
>说明</H2
>bool <B
CLASS="methodname"
>db2_fetch_row</B
> ( resource stmt [, int row_number] )<BR
></BR
><P
>&#13;   Use <B
CLASS="function"
>db2_fetch_row()</B
> 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
>&#13;   To retrieve individual fields from the result set, call the
   <A
HREF="function.db2-result.html"
><B
CLASS="function"
>db2_result()</B
></A
> function.
  </P
><P
>&#13;   Rather than calling <B
CLASS="function"
>db2_fetch_row()</B
> and
   <A
HREF="function.db2-result.html"
><B
CLASS="function"
>db2_result()</B
></A
>, most applications will call one of
   <A
HREF="function.db2-fetch-assoc.html"
><B
CLASS="function"
>db2_fetch_assoc()</B
></A
>, <A
HREF="function.db2-fetch-both.html"
><B
CLASS="function"
>db2_fetch_both()</B
></A
>,
   or <A
HREF="function.db2-fetch-array.html"
><B
CLASS="function"
>db2_fetch_array()</B
></A
> to advance the result set pointer
   and return a complete row as an array.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN81010"
></A
><H2
>参数</H2
><P
>&#13;   <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><CODE
CLASS="parameter"
>stmt</CODE
></DT
><DD
><P
>&#13;       A valid <TT
CLASS="literal"
>stmt</TT
> resource.
      </P
></DD
><DT
><CODE
CLASS="parameter"
>row_number</CODE
></DT
><DD
><P
>&#13;       With scrollable cursors, you can request a specific row number in the
       result set. Row numbering is 1-indexed.
      </P
></DD
></DL
></DIV
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN81025"
></A
><H2
>返回值</H2
><P
>&#13;   Returns <TT
CLASS="constant"
><B
>TRUE</B
></TT
> if the requested row exists in the result set. Returns
   <TT
CLASS="constant"
><B
>FALSE</B
></TT
> if the requested row does not exist in the result set.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN81030"
></A
><H2
>范例</H2
><P
>&#13;   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN81033"
></A
><P
><B
>例 1. Iterating through a result set</B
></P
><P
>&#13;     The following example demonstrates how to iterate through a result set
     with <B
CLASS="function"
>db2_fetch_row()</B
> and retrieve columns from the
     result set with <A
HREF="function.db2-result.html"
><B
CLASS="function"
>db2_result()</B
></A
>.
    </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />$sql </font><font color="#007700">= </font><font color="#DD0000">'SELECT name, breed FROM animals WHERE weight &lt; ?'</font><font color="#007700">;<br /></font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">db2_prepare</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#0000BB">$sql</font><font color="#007700">);<br /></font><font color="#0000BB">db2_execute</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">, array(</font><font color="#0000BB">10</font><font color="#007700">));<br />while (</font><font color="#0000BB">db2_fetch_row</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$name </font><font color="#007700">= </font><font color="#0000BB">db2_result</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">, </font><font color="#0000BB">0</font><font color="#007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$breed </font><font color="#007700">= </font><font color="#0000BB">db2_result</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">, </font><font color="#0000BB">1</font><font color="#007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;print </font><font color="#DD0000">"$name $breed"</font><font color="#007700">;<br />}<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>上例将输出:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>cat Pook
gold fish Bubbles
budgerigar Gizmo
goat Rickety Ride</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN81041"
></A
><P
><B
>例 2. i5/OS recommended alternatives to db2_fetch_row/db2_result</B
></P
><P
>&#13;     On i5/OS it is recommended that you use <A
HREF="function.db2-fetch-both.html"
><B
CLASS="function"
>db2_fetch_both()</B
></A
>, 
     <A
HREF="function.db2-fetch-array.html"
><B
CLASS="function"
>db2_fetch_array()</B
></A
>, or <A
HREF="function.db2-fetch-object.html"
><B
CLASS="function"
>db2_fetch_object()</B
></A
> 
     over <B
CLASS="function"
>db2_fetch_row()</B
>/<A
HREF="function.db2-result.html"
><B
CLASS="function"
>db2_result()</B
></A
>. In general 
     <B
CLASS="function"
>db2_fetch_row()</B
>/<A
HREF="function.db2-result.html"
><B
CLASS="function"
>db2_result()</B
></A
> have more issues 
     with various column types in <TT
CLASS="literal"
>EBCIDIC</TT
> to <TT
CLASS="literal"
>ASCII</TT
> 
     translation, including possible truncation in <TT
CLASS="literal"
>DBCS</TT
> applications. 
     You may also find the performance of <A
HREF="function.db2-fetch-both.html"
><B
CLASS="function"
>db2_fetch_both()</B
></A
>, 
     <A
HREF="function.db2-fetch-array.html"
><B
CLASS="function"
>db2_fetch_array()</B
></A
>, and <A
HREF="function.db2-fetch-object.html"
><B
CLASS="function"
>db2_fetch_object()</B
></A
> to 
     be superior to <B
CLASS="function"
>db2_fetch_row()</B
>/<A
HREF="function.db2-result.html"
><B
CLASS="function"
>db2_result()</B
></A
>.
    </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />&nbsp;&nbsp;$conn </font><font color="#007700">= </font><font color="#0000BB">db2_connect</font><font color="#007700">(</font><font color="#DD0000">""</font><font color="#007700">,</font><font color="#DD0000">""</font><font color="#007700">,</font><font color="#DD0000">""</font><font color="#007700">);<br />&nbsp;&nbsp;</font><font color="#0000BB">$sql </font><font color="#007700">= </font><font color="#DD0000">'SELECT SPECIFIC_SCHEMA, SPECIFIC_NAME, ROUTINE_SCHEMA, ROUTINE_NAME, ROUTINE_TYPE, ROUTINE_CREATED, ROUTINE_BODY, IN_PARMS, OUT_PARMS, INOUT_PARMS, PARAMETER_STYLE, EXTERNAL_NAME, EXTERNAL_LANGUAGE FROM QSYS2.SYSROUTINES FETCH FIRST 2 ROWS ONLY'</font><font color="#007700">;<br />&nbsp;&nbsp;</font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">db2_exec</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#0000BB">$sql</font><font color="#007700">, array(</font><font color="#DD0000">'cursor' </font><font color="#007700">=&gt; </font><font color="#0000BB">DB2_SCROLLABLE</font><font color="#007700">));<br />&nbsp;&nbsp;while (</font><font color="#0000BB">$row </font><font color="#007700">= </font><font color="#0000BB">db2_fetch_both</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">)){<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"&lt;br&gt;db2_fetch_both </font><font color="#007700">{</font><font color="#DD0000">$row</font><font color="#007700">[</font><font color="#DD0000">'SPECIFIC_NAME'</font><font color="#007700">]}</font><font color="#DD0000"> </font><font color="#007700">{</font><font color="#DD0000">$row</font><font color="#007700">[</font><font color="#DD0000">'ROUTINE_CREATED'</font><font color="#007700">]}</font><font color="#DD0000"> </font><font color="#007700">{</font><font color="#DD0000">$row</font><font color="#007700">[</font><font color="#DD0000">5</font><font color="#007700">]}</font><font color="#DD0000">"</font><font color="#007700">;<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;</font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">db2_exec</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#0000BB">$sql</font><font color="#007700">, array(</font><font color="#DD0000">'cursor' </font><font color="#007700">=&gt; </font><font color="#0000BB">DB2_SCROLLABLE</font><font color="#007700">));<br />&nbsp;&nbsp;while (</font><font color="#0000BB">$row </font><font color="#007700">= </font><font color="#0000BB">db2_fetch_array</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">)){<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"&lt;br&gt;db2_fetch_array </font><font color="#007700">{</font><font color="#DD0000">$row</font><font color="#007700">[</font><font color="#DD0000">1</font><font color="#007700">]}</font><font color="#DD0000">&nbsp;&nbsp;</font><font color="#007700">{</font><font color="#DD0000">$row</font><font color="#007700">[</font><font color="#DD0000">5</font><font color="#007700">]}</font><font color="#DD0000">"</font><font color="#007700">;<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;</font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">db2_exec</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#0000BB">$sql</font><font color="#007700">, array(</font><font color="#DD0000">'cursor' </font><font color="#007700">=&gt; </font><font color="#0000BB">DB2_SCROLLABLE</font><font color="#007700">));<br />&nbsp;&nbsp;while (</font><font color="#0000BB">$row </font><font color="#007700">= </font><font color="#0000BB">db2_fetch_object</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">)){<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"&lt;br&gt;db2_fetch_object </font><font color="#007700">{</font><font color="#DD0000">$row</font><font color="#007700">-&gt;</font><font color="#DD0000">SPECIFIC_NAME</font><font color="#007700">}</font><font color="#DD0000"> </font><font color="#007700">{</font><font color="#DD0000">$row</font><font color="#007700">-&gt;</font><font color="#DD0000">ROUTINE_CREATED</font><font color="#007700">}</font><font color="#DD0000">"</font><font color="#007700">;<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;</font><font color="#0000BB">db2_close</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">);<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>上例将输出:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>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
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN81062"
></A
><H2
>参见</H2
><P
>&#13;   <P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
><A
HREF="function.db2-fetch-array.html"
><B
CLASS="function"
>db2_fetch_array()</B
></A
></TD
></TR
><TR
><TD
><A
HREF="function.db2-fetch-assoc.html"
><B
CLASS="function"
>db2_fetch_assoc()</B
></A
></TD
></TR
><TR
><TD
><A
HREF="function.db2-fetch-both.html"
><B
CLASS="function"
>db2_fetch_both()</B
></A
></TD
></TR
><TR
><TD
><A
HREF="function.db2-fetch-object.html"
><B
CLASS="function"
>db2_fetch_object()</B
></A
></TD
></TR
><TR
><TD
><A
HREF="function.db2-result.html"
><B
CLASS="function"
>db2_result()</B
></A
></TD
></TR
></TBODY
></TABLE
><P
></P
>
  </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.db2-fetch-object.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>起始页</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.db2-field-display-size.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>db2_fetch_object</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.ibm-db2.html"
ACCESSKEY="U"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>db2_field_display_size</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>