Sophie

Sophie

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

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_assoc</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_array"
HREF="function.db2-fetch-array.html"><LINK
REL="NEXT"
TITLE="db2_fetch_both"
HREF="function.db2-fetch-both.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-array.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.db2-fetch-both.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.db2-fetch-assoc"
></A
>db2_fetch_assoc</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN80785"
></A
><P
>    (PECL)</P
>db2_fetch_assoc&nbsp;--&nbsp;
   Returns an array, indexed by column name, representing a row in a result set
  </DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN80788"
></A
><H2
>说明</H2
>array <B
CLASS="methodname"
>db2_fetch_assoc</B
> ( resource stmt [, int row_number] )<BR
></BR
><P
>&#13;   Returns an array, indexed by column name, representing a row in a result
   set.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN80800"
></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 containing a result set.
      </P
></DD
><DT
><CODE
CLASS="parameter"
>row_number</CODE
></DT
><DD
><P
>&#13;       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
></DL
></DIV
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN80815"
></A
><H2
>返回值</H2
><P
>&#13;   Returns an associative array with column values indexed by the column name
   representing the next or requested row in the result set. Returns <TT
CLASS="constant"
><B
>FALSE</B
></TT
> if
   there are no rows left in the result set, or if the row requested by
   <CODE
CLASS="parameter"
>row_number</CODE
> does not exist in the result set.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN80820"
></A
><H2
>范例</H2
><P
>&#13;   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN80823"
></A
><P
><B
>例 1. Iterating through a forward-only cursor</B
></P
><P
>&#13;     If you call <B
CLASS="function"
>db2_fetch_assoc()</B
> without a specific row
     number, it automatically retrieves the next row in the result set.
    </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /><br />$sql </font><font color="#007700">= </font><font color="#DD0000">"SELECT id, name, breed, weight FROM animals ORDER BY breed"</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">$result </font><font color="#007700">= </font><font color="#0000BB">db2_execute</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">);<br /><br />while (</font><font color="#0000BB">$row </font><font color="#007700">= </font><font color="#0000BB">db2_fetch_assoc</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">printf </font><font color="#007700">(</font><font color="#DD0000">"%-5d %-16s %-32s %10s\n"</font><font color="#007700">, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$row</font><font color="#007700">[</font><font color="#DD0000">'ID'</font><font color="#007700">], </font><font color="#0000BB">$row</font><font color="#007700">[</font><font color="#DD0000">'NAME'</font><font color="#007700">], </font><font color="#0000BB">$row</font><font color="#007700">[</font><font color="#DD0000">'BREED'</font><font color="#007700">], </font><font color="#0000BB">$row</font><font color="#007700">[</font><font color="#DD0000">'WEIGHT'</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"
>0     Pook             cat                                    3.20
5     Rickety Ride     goat                                   9.70
2     Smarty           horse                                350.00</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="AEN80830"
></A
><P
><B
>例 2. Retrieving specific rows with <B
CLASS="function"
>db2_fetch_assoc()</B
>
     from a scrollable cursor</B
></P
><P
>&#13;     If your result set uses a scrollable cursor, you can call
     <B
CLASS="function"
>db2_fetch_assoc()</B
> with a specific row number. The
     following example retrieves every other row in the result set, starting
     with the second row.
    </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /><br />$sql </font><font color="#007700">= </font><font color="#DD0000">"SELECT id, name, breed, weight FROM animals ORDER BY breed"</font><font color="#007700">;<br /></font><font color="#0000BB">$result </font><font color="#007700">= </font><font color="#0000BB">db2_exec</font><font color="#007700">(</font><font color="#0000BB">$stmt</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 /><br /></font><font color="#0000BB">$i</font><font color="#007700">=</font><font color="#0000BB">2</font><font color="#007700">;<br />while (</font><font color="#0000BB">$row </font><font color="#007700">= </font><font color="#0000BB">db2_fetch_assoc</font><font color="#007700">(</font><font color="#0000BB">$result</font><font color="#007700">, </font><font color="#0000BB">$i</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">printf </font><font color="#007700">(</font><font color="#DD0000">"%-5d %-16s %-32s %10s\n"</font><font color="#007700">, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$row</font><font color="#007700">[</font><font color="#DD0000">'ID'</font><font color="#007700">], </font><font color="#0000BB">$row</font><font color="#007700">[</font><font color="#DD0000">'NAME'</font><font color="#007700">], </font><font color="#0000BB">$row</font><font color="#007700">[</font><font color="#DD0000">'BREED'</font><font color="#007700">], </font><font color="#0000BB">$row</font><font color="#007700">[</font><font color="#DD0000">'WEIGHT'</font><font color="#007700">]);<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$i </font><font color="#007700">= </font><font color="#0000BB">$i </font><font color="#007700">+ </font><font color="#0000BB">2</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"
>0     Pook             cat                                    3.20
5     Rickety Ride     goat                                   9.70
2     Smarty           horse                                350.00</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN80838"
></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-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-fetch-row.html"
><B
CLASS="function"
>db2_fetch_row()</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-array.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-fetch-both.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>db2_fetch_array</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_fetch_both</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>