<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >msql_fetch_object</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_fetch_field" HREF="function.msql-fetch-field.html"><LINK REL="NEXT" TITLE="msql_fetch_row" HREF="function.msql-fetch-row.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-fetch-field.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-row.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.msql-fetch-object" ></A >msql_fetch_object</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN130234" ></A ><P > (PHP 3, PHP 4, PHP 5)</P >msql_fetch_object -- Fetch row as object</DIV ><DIV CLASS="refsect1" ><A NAME="AEN130237" ></A ><H2 >说明</H2 >object <B CLASS="methodname" >msql_fetch_object</B > ( resource result )<BR ></BR ><P > <B CLASS="function" >msql_fetch_object()</B > is similar to <A HREF="function.msql-fetch-array.html" ><B CLASS="function" >msql_fetch_array()</B ></A >, with one difference - an object is returned, instead of an array. Indirectly, that means that you can only access the data by the field names, and not by their offsets (numbers are illegal property names). </P ><P > Speed-wise, the function is identical to <A HREF="function.msql-fetch-array.html" ><B CLASS="function" >msql_fetch_array()</B ></A >, and almost as quick as <A HREF="function.msql-fetch-row.html" ><B CLASS="function" >msql_fetch_row()</B ></A > (the difference is insignificant). </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN130251" ></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 ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN130262" ></A ><H2 >返回值</H2 ><P > Returns an object with properties that correspond 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="AEN130266" ></A ><H2 >范例</H2 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN130269" ></A ><P ><B >例 1. <B CLASS="function" >msql_fetch_object()</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_object</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="#0000BB">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="#0000BB">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="AEN130273" ></A ><H2 >更新日志</H2 ><P > <DIV CLASS="informaltable" ><P ></P ><A NAME="AEN130276" ></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="AEN130287" ></A ><H2 >参见</H2 ><P > <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD ><A HREF="function.msql-fetch-array.html" ><B CLASS="function" >msql_fetch_array()</B ></A ></TD ></TR ><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-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-fetch-field.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-row.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >msql_fetch_field</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_row</TD ></TR ></TABLE ></DIV ></BODY ></HTML >