<!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="Manual do 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" >Manual do PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.sesam-execimm.html" ACCESSKEY="P" >Anterior</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" >Próxima</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="AEN201931" ></A ><P > (PHP 3 CVS only)</P >sesam_fetch_array -- Fetch one row as an associative array</DIV ><DIV CLASS="refsect1" ><A NAME="AEN201934" ></A ><H2 >Descrição</H2 >array <B CLASS="methodname" >sesam_fetch_array</B > ( string result_id [, int whence [, int offset]] )<BR ></BR ><P > <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 > <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 > 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="AEN201955" ></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 > 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="AEN201958" ></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 > 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="AEN201966" ></A ><H2 >Parâmetros</H2 ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >result_id</CODE ></DT ><DD ><P > 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 > <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="AEN201982" ></A ><P ><B >Tabela 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 > 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 > 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 > 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 > 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 > 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 > 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 > 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 > 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="AEN202042" ></A ><H2 >Valores de retornado</H2 ><P > 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="AEN202046" ></A ><H2 >Exemplos</H2 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN202049" ></A ><P ><B >Exemplo 1. SESAM fetch array</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?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 /> </font><font color="#DD0000">" 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 /> </font><font color="#DD0000">" 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 /> </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">"<table border=\"1\">\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">)) && </font><font color="#0000BB">count</font><font color="#007700">(</font><font color="#0000BB">$row</font><font color="#007700">) > </font><font color="#0000BB">0</font><font color="#007700">) {<br /> echo </font><font color="#DD0000">"<tr>\n"</font><font color="#007700">;<br /> echo </font><font color="#DD0000">"<td>" </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">"</td>\n"</font><font color="#007700">;<br /> echo </font><font color="#DD0000">"<td>" </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">"</td>\n"</font><font color="#007700">;<br /> echo </font><font color="#DD0000">"<td>" </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">"</td>\n"</font><font color="#007700">;<br /> echo </font><font color="#DD0000">"</tr>\n"</font><font color="#007700">;<br />}<br />echo </font><font color="#DD0000">"</table>\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">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN202052" ></A ><H2 >Veja também</H2 ><P > <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" >Anterior</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Principal</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.sesam-fetch-result.html" ACCESSKEY="N" >Próxima</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" >Acima</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >sesam_fetch_result</TD ></TR ></TABLE ></DIV ></BODY ></HTML >