Sophie

Sophie

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

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
>sesam_fetch_array</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="PHP 手册"
HREF="index.html"><LINK
REL="UP"
TITLE="SESAM Database Functions"
HREF="ref.sesam.html"><LINK
REL="PREVIOUS"
TITLE="sesam_execimm"
HREF="function.sesam-execimm.html"><LINK
REL="NEXT"
TITLE="sesam_fetch_result"
HREF="function.sesam-fetch-result.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.sesam-execimm.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.sesam-fetch-result.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.sesam-fetch-array"
></A
>sesam_fetch_array</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN206578"
></A
><P
>    (PHP 3 CVS only)</P
>sesam_fetch_array&nbsp;--&nbsp;Fetch one row as an associative array</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN206581"
></A
><H2
>说明</H2
>array <B
CLASS="methodname"
>sesam_fetch_array</B
> ( string result_id [, int whence [, int offset]] )<BR
></BR
><P
>&#13;   <B
CLASS="function"
>sesam_fetch_array()</B
> is an alternative version
   of <A
HREF="function.sesam-fetch-row.html"
><B
CLASS="function"
>sesam_fetch_row()</B
></A
>.  Instead of storing the
   data in the numeric indices of the result array, it stores the
   data in associative indices, using the field names as keys.
  </P
><P
>&#13;   <B
CLASS="function"
>sesam_fetch_array()</B
> fetches one row of data
   from the result associated with the specified result identifier.
   The row is returned as an associative array.  Each result column
   is stored with an associative index equal to its column
   (aka. field) name. The column names are converted to lower case.
  </P
><P
>&#13;   Columns without a field name (e.g., results of arithmetic
   operations) and empty fields are not stored in the array.  Also,
   if two or more columns of the result have the same column names,
   the later column will take precedence.  In this situation, either
   call <A
HREF="function.sesam-fetch-row.html"
><B
CLASS="function"
>sesam_fetch_row()</B
></A
> or make an alias for
   the column.
   <DIV
CLASS="informalexample"
><P
></P
><A
NAME="AEN206602"
></A
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="sesam"
>SELECT TBL1.COL AS FOO, TBL2.COL AS BAR FROM TBL1, TBL2</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
>
  </P
><P
>&#13;   A special handling allows fetching "multiple field" columns
   (which would otherwise all have the same column names).  For each
   column of a "multiple field", the index name is constructed by
   appending the string "(n)" where n is the sub-index of the
   multiple field column, ranging from 1 to its declared repetition
   factor. The indices are NOT zero based, in order to match the
   nomenclature used in the respective query syntax.  For a column
   declared as:
   <DIV
CLASS="informalexample"
><P
></P
><A
NAME="AEN206605"
></A
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="sesam"
>CREATE TABLE ... ( ... MULTI(3) INT )</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
>
   the associative indices used for the individual "multiple field"
   columns would be <TT
CLASS="literal"
>"multi(1)"</TT
>,
   <TT
CLASS="literal"
>"multi(2)"</TT
>, and <TT
CLASS="literal"
>"multi(3)"</TT
>
   respectively.
  </P
><P
>&#13;   Subsequent calls to <B
CLASS="function"
>sesam_fetch_array()</B
> would
   return the next (or prior, or n'th next/prior, depending on the
   scroll attributes) row in the result set, or <TT
CLASS="constant"
><B
>FALSE</B
></TT
> if there are no more rows.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN206613"
></A
><H2
>参数</H2
><P
>&#13;   <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><CODE
CLASS="parameter"
>result_id</CODE
></DT
><DD
><P
>&#13;       A valid result id returned by <A
HREF="function.sesam-query.html"
><B
CLASS="function"
>sesam_query()</B
></A
>.
      </P
></DD
><DT
><CODE
CLASS="parameter"
>whence</CODE
></DT
><DD
><P
>&#13;       <CODE
CLASS="parameter"
>whence</CODE
> is an optional
       parameter for a fetch operation on "scrollable" cursors, which
       can be set to the following predefined constants:
       <DIV
CLASS="table"
><A
NAME="AEN206629"
></A
><P
><B
>表 1. Valid values for <CODE
CLASS="parameter"
>"whence"</CODE
> parameter</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><COL><THEAD
><TR
><TH
>Value</TH
><TH
>Constant</TH
><TH
>Meaning</TH
></TR
></THEAD
><TBODY
><TR
><TD
>0</TD
><TD
><TT
CLASS="constant"
><B
>SESAM_SEEK_NEXT</B
></TT
></TD
><TD
>&#13;            read sequentially (after fetch, the internal default is set
            to <TT
CLASS="constant"
><B
>SESAM_SEEK_NEXT</B
></TT
>)
           </TD
></TR
><TR
><TD
>1</TD
><TD
><TT
CLASS="constant"
><B
>SESAM_SEEK_PRIOR</B
></TT
></TD
><TD
>&#13;            read sequentially backwards (after fetch, the internal
            default is set to <TT
CLASS="constant"
><B
>SESAM_SEEK_PRIOR</B
></TT
>)
           </TD
></TR
><TR
><TD
>2</TD
><TD
><TT
CLASS="constant"
><B
>SESAM_SEEK_FIRST</B
></TT
></TD
><TD
>&#13;            rewind to first row (after fetch, the default is set to
            <TT
CLASS="constant"
><B
>SESAM_SEEK_NEXT</B
></TT
>)
           </TD
></TR
><TR
><TD
>3</TD
><TD
><TT
CLASS="constant"
><B
>SESAM_SEEK_LAST</B
></TT
></TD
><TD
>&#13;            seek to last row (after fetch, the default is set to
            <TT
CLASS="constant"
><B
>SESAM_SEEK_PRIOR</B
></TT
>)
           </TD
></TR
><TR
><TD
>4</TD
><TD
><TT
CLASS="constant"
><B
>SESAM_SEEK_ABSOLUTE</B
></TT
></TD
><TD
>&#13;            seek to absolute row number given as
            <CODE
CLASS="parameter"
>offset</CODE
> (Zero-based. After fetch, the
            internal default is set to
            <TT
CLASS="constant"
><B
>SESAM_SEEK_ABSOLUTE</B
></TT
>, and the internal
            offset value is auto-incremented)
           </TD
></TR
><TR
><TD
>5</TD
><TD
><TT
CLASS="constant"
><B
>SESAM_SEEK_RELATIVE</B
></TT
></TD
><TD
>&#13;            seek relative to current scroll position, where
            <CODE
CLASS="parameter"
>offset</CODE
> can be a positive or negative
            offset value.
           </TD
></TR
></TBODY
></TABLE
></DIV
>
       This parameter is only valid for "scrollable" cursors.
      </P
><P
>&#13;       When using "scrollable" cursors, the cursor can be freely positioned
       on the result set. If the <CODE
CLASS="parameter"
>whence</CODE
> parameter is
       omitted, the global default values for the scrolling type (initialized
       to: <TT
CLASS="constant"
><B
>SESAM_SEEK_NEXT</B
></TT
>, and settable by
       <A
HREF="function.sesam-seek-row.html"
><B
CLASS="function"
>sesam_seek_row()</B
></A
>) are used. If
       <CODE
CLASS="parameter"
>whence</CODE
> is supplied, its value replaces the
       global default.
      </P
></DD
><DT
><CODE
CLASS="parameter"
>offset</CODE
></DT
><DD
><P
>&#13;       Only evaluated (and required) if <CODE
CLASS="parameter"
>whence</CODE
> is
       either <TT
CLASS="constant"
><B
>SESAM_SEEK_RELATIVE</B
></TT
> or
       <TT
CLASS="constant"
><B
>SESAM_SEEK_ABSOLUTE</B
></TT
>. This parameter is only
       valid for "scrollable" cursors.
      </P
></DD
></DL
></DIV
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN206689"
></A
><H2
>返回值</H2
><P
>&#13;   Returns an array that corresponds to the fetched row, or
   <TT
CLASS="constant"
><B
>FALSE</B
></TT
> if there are no more rows.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN206693"
></A
><H2
>范例</H2
><P
>&#13;   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN206696"
></A
><P
><B
>例 1. SESAM fetch array</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />$result </font><font color="#007700">= </font><font color="#0000BB">sesam_query</font><font color="#007700">(</font><font color="#DD0000">"SELECT * FROM phone\n" </font><font color="#007700">.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">"&nbsp;&nbsp;WHERE LASTNAME='" </font><font color="#007700">. </font><font color="#0000BB">strtoupper</font><font color="#007700">(</font><font color="#0000BB">$name</font><font color="#007700">) . </font><font color="#DD0000">"'\n"</font><font color="#007700">.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">"&nbsp;&nbsp;ORDER BY FIRSTNAME"</font><font color="#007700">, </font><font color="#0000BB">1</font><font color="#007700">);<br />if (!</font><font color="#0000BB">$result</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">/* ... error ... */<br /></font><font color="#007700">}<br /></font><font color="#FF8000">// print the table:<br /></font><font color="#007700">echo </font><font color="#DD0000">"&lt;table border=\"1\"&gt;\n"</font><font color="#007700">;<br />while ((</font><font color="#0000BB">$row </font><font color="#007700">= </font><font color="#0000BB">sesam_fetch_array</font><font color="#007700">(</font><font color="#0000BB">$result</font><font color="#007700">)) &amp;&amp; </font><font color="#0000BB">count</font><font color="#007700">(</font><font color="#0000BB">$row</font><font color="#007700">) &gt; </font><font color="#0000BB">0</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"&lt;tr&gt;\n"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"&lt;td&gt;" </font><font color="#007700">. </font><font color="#0000BB">htmlspecialchars</font><font color="#007700">(</font><font color="#0000BB">$row</font><font color="#007700">[</font><font color="#DD0000">"firstname"</font><font color="#007700">]) . </font><font color="#DD0000">"&lt;/td&gt;\n"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"&lt;td&gt;" </font><font color="#007700">. </font><font color="#0000BB">htmlspecialchars</font><font color="#007700">(</font><font color="#0000BB">$row</font><font color="#007700">[</font><font color="#DD0000">"lastname"</font><font color="#007700">]) . </font><font color="#DD0000">"&lt;/td&gt;\n"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"&lt;td&gt;" </font><font color="#007700">. </font><font color="#0000BB">htmlspecialchars</font><font color="#007700">(</font><font color="#0000BB">$row</font><font color="#007700">[</font><font color="#DD0000">"phoneno"</font><font color="#007700">]) . </font><font color="#DD0000">"&lt;/td&gt;\n"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"&lt;/tr&gt;\n"</font><font color="#007700">;<br />}<br />echo </font><font color="#DD0000">"&lt;/table&gt;\n"</font><font color="#007700">;<br /></font><font color="#0000BB">sesam_free_result</font><font color="#007700">(</font><font color="#0000BB">$result</font><font color="#007700">);<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN206699"
></A
><H2
>参见</H2
><P
>&#13;   <P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
><A
HREF="function.sesam-fetch-row.html"
><B
CLASS="function"
>sesam_fetch_row()</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.sesam-execimm.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.sesam-fetch-result.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>sesam_execimm</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.sesam.html"
ACCESSKEY="U"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>sesam_fetch_result</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>