Sophie

Sophie

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

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
>mysql_fetch_field</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="PHP 手册"
HREF="index.html"><LINK
REL="UP"
TITLE="MySQL 函数"
HREF="ref.mysql.html"><LINK
REL="PREVIOUS"
TITLE="mysql_fetch_assoc"
HREF="function.mysql-fetch-assoc.html"><LINK
REL="NEXT"
TITLE="mysql_fetch_lengths"
HREF="function.mysql-fetch-lengths.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.mysql-fetch-assoc.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.mysql-fetch-lengths.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.mysql-fetch-field"
></A
>mysql_fetch_field</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN135529"
></A
><P
>    (PHP 3, PHP 4, PHP 5)</P
>mysql_fetch_field&nbsp;--&nbsp;
     从结果集中取得列信息并作为对象返回
    </DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN135532"
></A
><H2
>说明</H2
>object <B
CLASS="methodname"
>mysql_fetch_field</B
> ( resource result [, int field_offset] )<BR
></BR
><P
>&#13;     返回一个包含字段信息的对象。
    </P
><P
>&#13;     <B
CLASS="function"
>mysql_fetch_field()</B
>
     可以用来从某个查询结果中取得字段的信息。如果没有指定字段偏移量,则下一个尚未被
     <B
CLASS="function"
>mysql_fetch_field()</B
> 取得的字段被提取。
    </P
><P
>&#13;     对象的属性为:
     <P
></P
><UL
><LI
><P
>&#13;        name - 列名
       </P
></LI
><LI
><P
>&#13;        table - 该列所在的表名
       </P
></LI
><LI
><P
>&#13;        max_length - 该列最大长度
       </P
></LI
><LI
><P
>&#13;        not_null - 1,如果该列不能为 <TT
CLASS="constant"
><B
>NULL</B
></TT
>
       </P
></LI
><LI
><P
>&#13;        primary_key - 1,如果该列是 primary key
       </P
></LI
><LI
><P
>&#13;        unique_key - 1,如果该列是 unique key
       </P
></LI
><LI
><P
>&#13;        multiple_key - 1,如果该列是 non-unique key
       </P
></LI
><LI
><P
>&#13;        numeric - 1,如果该列是 numeric
       </P
></LI
><LI
><P
>&#13;        blob - 1,如果该列是 BLOB
       </P
></LI
><LI
><P
>&#13;        type - 该列的类型
       </P
></LI
><LI
><P
>&#13;        unsigned - 1,如果该列是无符号数
       </P
></LI
><LI
><P
>&#13;        zerofill - 1,如果该列是 zero-filled
       </P
></LI
></UL
>
    </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>注意: </B
>本函数返回的字段名是<SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>区分大小写</I
></SPAN
>的。</P
></BLOCKQUOTE
></DIV
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN135578"
></A
><P
><B
>例 1. <B
CLASS="function"
>mysql_fetch_field()</B
></B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />mysql_connect</font><font color="#007700">(</font><font color="#DD0000">'localhost:3306'</font><font color="#007700">, </font><font color="#0000BB">$user</font><font color="#007700">, </font><font color="#0000BB">$password</font><font color="#007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;or die(</font><font color="#DD0000">"Could not connect: " </font><font color="#007700">. </font><font color="#0000BB">mysql_error</font><font color="#007700">());<br /></font><font color="#0000BB">mysql_select_db</font><font color="#007700">(</font><font color="#DD0000">"database"</font><font color="#007700">);<br /></font><font color="#0000BB">$result </font><font color="#007700">= </font><font color="#0000BB">mysql_query</font><font color="#007700">(</font><font color="#DD0000">"select * from table"</font><font color="#007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;or die(</font><font color="#DD0000">"Query failed: " </font><font color="#007700">. </font><font color="#0000BB">mysql_error</font><font color="#007700">());<br /></font><font color="#FF8000">/* get column metadata */<br /></font><font color="#0000BB">$i </font><font color="#007700">= </font><font color="#0000BB">0</font><font color="#007700">;<br />while (</font><font color="#0000BB">$i </font><font color="#007700">&lt; </font><font color="#0000BB">mysql_num_fields</font><font color="#007700">(</font><font color="#0000BB">$result</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"Information for column $i:&lt;br /&gt;</font><font color="#007700">\n</font><font color="#DD0000">"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$meta </font><font color="#007700">= </font><font color="#0000BB">mysql_fetch_field</font><font color="#007700">(</font><font color="#0000BB">$result</font><font color="#007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;if (!</font><font color="#0000BB">$meta</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"No information available&lt;br /&gt;\n"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"&lt;pre&gt;<br />blob:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$meta</font><font color="#007700">-&gt;</font><font color="#DD0000">blob<br />max_length:&nbsp;&nbsp;&nbsp;$meta</font><font color="#007700">-&gt;</font><font color="#DD0000">max_length<br />multiple_key: $meta</font><font color="#007700">-&gt;</font><font color="#DD0000">multiple_key<br />name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$meta</font><font color="#007700">-&gt;</font><font color="#DD0000">name<br />not_null:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$meta</font><font color="#007700">-&gt;</font><font color="#DD0000">not_null<br />numeric:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$meta</font><font color="#007700">-&gt;</font><font color="#DD0000">numeric<br />primary_key:&nbsp;&nbsp;$meta</font><font color="#007700">-&gt;</font><font color="#DD0000">primary_key<br />table:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$meta</font><font color="#007700">-&gt;</font><font color="#DD0000">table<br />type:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$meta</font><font color="#007700">-&gt;</font><font color="#DD0000">type<br />unique_key:&nbsp;&nbsp;&nbsp;$meta</font><font color="#007700">-&gt;</font><font color="#DD0000">unique_key<br />unsigned:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$meta</font><font color="#007700">-&gt;</font><font color="#DD0000">unsigned<br />zerofill:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$meta</font><font color="#007700">-&gt;</font><font color="#DD0000">zerofill<br />&lt;/pre&gt;"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$i</font><font color="#007700">++;<br />}<br /></font><font color="#0000BB">mysql_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
><P
>&#13;     参见 <A
HREF="function.mysql-field-seek.html"
><B
CLASS="function"
>mysql_field_seek()</B
></A
>。
    </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.mysql-fetch-assoc.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.mysql-fetch-lengths.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>mysql_fetch_assoc</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.mysql.html"
ACCESSKEY="U"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>mysql_fetch_lengths</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>