<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >msql_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="mSQL Functions" HREF="ref.msql.html"><LINK REL="PREVIOUS" TITLE="msql_error" HREF="function.msql-error.html"><LINK REL="NEXT" TITLE="msql_fetch_field" HREF="function.msql-fetch-field.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.msql-error.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.msql-fetch-field.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.msql-fetch-array" ></A >msql_fetch_array</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN130097" ></A ><P > (PHP 3, PHP 4, PHP 5)</P >msql_fetch_array -- Fetch row as array</DIV ><DIV CLASS="refsect1" ><A NAME="AEN130100" ></A ><H2 >说明</H2 >array <B CLASS="methodname" >msql_fetch_array</B > ( resource result [, int result_type] )<BR ></BR ><P > <B CLASS="function" >msql_fetch_array()</B > is an extended version of <A HREF="function.msql-fetch-row.html" ><B CLASS="function" >msql_fetch_row()</B ></A >. In addition to storing the data in the numeric indices of the result array, it also stores the data in associative indices, using the field names as keys. </P ><P > An important thing to note is that using <B CLASS="function" >msql_fetch_array()</B > is NOT significantly slower than using <A HREF="function.msql-fetch-row.html" ><B CLASS="function" >msql_fetch_row()</B ></A >, while it provides a significant added value. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN130117" ></A ><H2 >参数</H2 ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" > result</CODE ></DT ><DD ><P >返回类型为 <A HREF="language.types.resource.html" ><B CLASS="type" >resource</B ></A > 的结果集。该结果集从 <A HREF="function.msql-query.html" ><B CLASS="function" >msql_query()</B ></A > 的调用中得到。</P ></DD ><DT ><CODE CLASS="parameter" >result_type</CODE ></DT ><DD ><P > A constant that can take the following values: <TT CLASS="constant" ><B >MSQL_ASSOC</B ></TT >, <TT CLASS="constant" ><B >MSQL_NUM</B ></TT >, and <TT CLASS="constant" ><B >MSQL_BOTH</B ></TT > with <TT CLASS="constant" ><B >MSQL_BOTH</B ></TT > being the default. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN130137" ></A ><H2 >返回值</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="AEN130141" ></A ><H2 >范例</H2 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN130144" ></A ><P ><B >例 1. <B CLASS="function" >msql_fetch_array()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$con </font><font color="#007700">= </font><font color="#0000BB">msql_connect</font><font color="#007700">();<br />if (!</font><font color="#0000BB">$con</font><font color="#007700">) {<br /> die(</font><font color="#DD0000">'Server connection problem: ' </font><font color="#007700">. </font><font color="#0000BB">msql_error</font><font color="#007700">());<br />}<br /><br />if (!</font><font color="#0000BB">msql_select_db</font><font color="#007700">(</font><font color="#DD0000">'test'</font><font color="#007700">, </font><font color="#0000BB">$con</font><font color="#007700">)) {<br /> die(</font><font color="#DD0000">'Database connection problem: ' </font><font color="#007700">. </font><font color="#0000BB">msql_error</font><font color="#007700">());<br />}<br /><br /></font><font color="#0000BB">$result </font><font color="#007700">= </font><font color="#0000BB">msql_query</font><font color="#007700">(</font><font color="#DD0000">'SELECT id, name FROM people'</font><font color="#007700">, </font><font color="#0000BB">$con</font><font color="#007700">);<br />if (!</font><font color="#0000BB">$result</font><font color="#007700">) {<br /> die(</font><font color="#DD0000">'Query execution problem: ' </font><font color="#007700">. </font><font color="#0000BB">msql_error</font><font color="#007700">());<br />}<br /><br />while (</font><font color="#0000BB">$row </font><font color="#007700">= </font><font color="#0000BB">msql_fetch_array</font><font color="#007700">(</font><font color="#0000BB">$result</font><font color="#007700">, </font><font color="#0000BB">MSQL_ASSOC</font><font color="#007700">)) {<br /> echo </font><font color="#0000BB">$row</font><font color="#007700">[</font><font color="#DD0000">'id'</font><font color="#007700">] . </font><font color="#DD0000">': ' </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="#DD0000">"\n"</font><font color="#007700">;<br />}<br /><br /></font><font color="#0000BB">msql_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="AEN130148" ></A ><H2 >更新日志</H2 ><P > <DIV CLASS="informaltable" ><P ></P ><A NAME="AEN130151" ></A ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><THEAD ><TR ><TH >版本</TH ><TH >说明</TH ></TR ></THEAD ><TBODY ><TR ><TD >4.3.11 and 5.0.4 </TD ><TD > A bug was fixed when retrieving data from columns containing <TT CLASS="constant" ><B >NULL</B ></TT > values. Such columns were not placed into the resulting array. </TD ></TR ></TBODY ></TABLE ><P ></P ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN130162" ></A ><H2 >参见</H2 ><P > <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD ><A HREF="function.msql-fetch-row.html" ><B CLASS="function" >msql_fetch_row()</B ></A ></TD ></TR ><TR ><TD ><A HREF="function.msql-fetch-object.html" ><B CLASS="function" >msql_fetch_object()</B ></A ></TD ></TR ><TR ><TD ><A HREF="function.msql-data-seek.html" ><B CLASS="function" >msql_data_seek()</B ></A ></TD ></TR ><TR ><TD ><A HREF="function.msql-result.html" ><B CLASS="function" >msql_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.msql-error.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.msql-fetch-field.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >msql_error</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.msql.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >msql_fetch_field</TD ></TR ></TABLE ></DIV ></BODY ></HTML >