<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >db2_num_fields</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="IBM DB2, Cloudscape and Apache Derby Functions" HREF="ref.ibm-db2.html"><LINK REL="PREVIOUS" TITLE="db2_next_result" HREF="function.db2-next-result.html"><LINK REL="NEXT" TITLE="db2_num_rows" HREF="function.db2-num-rows.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.db2-next-result.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.db2-num-rows.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.db2-num-fields" ></A >db2_num_fields</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN81887" ></A ><P > (PECL)</P >db2_num_fields -- Returns the number of fields contained in a result set </DIV ><DIV CLASS="refsect1" ><A NAME="AEN81890" ></A ><H2 >说明</H2 >int <B CLASS="methodname" >db2_num_fields</B > ( resource stmt )<BR ></BR ><P > Returns the number of fields contained in a result set. This is most useful for handling the result sets returned by dynamically generated queries, or for result sets returned by stored procedures, where your application cannot otherwise know how to retrieve and use the results. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN81899" ></A ><H2 >参数</H2 ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >stmt</CODE ></DT ><DD ><P > A valid statement resource containing a result set. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN81908" ></A ><H2 >返回值</H2 ><P > Returns an integer value representing the number of fields in the result set associated with the specified statement resource. Returns <TT CLASS="constant" ><B >FALSE</B ></TT > if the statement resource is not a valid input value. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN81912" ></A ><H2 >范例</H2 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN81915" ></A ><P ><B >例 1. Retrieving the number of fields in a result set</B ></P ><P > The following example demonstrates how to retrieve the number of fields returned in a result set. </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /><br />$sql </font><font color="#007700">= </font><font color="#DD0000">"SELECT id, name, breed, weight FROM animals ORDER BY breed"</font><font color="#007700">;<br /></font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">db2_prepare</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#0000BB">$sql</font><font color="#007700">);<br /></font><font color="#0000BB">db2_execute</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">, </font><font color="#0000BB">$sql</font><font color="#007700">);<br /></font><font color="#0000BB">$columns </font><font color="#007700">= </font><font color="#0000BB">db2_num_fields</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">);<br /><br />echo </font><font color="#DD0000">"There are </font><font color="#007700">{</font><font color="#DD0000">$columns</font><font color="#007700">}</font><font color="#DD0000"> columns in the result set."</font><font color="#007700">;<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P >上例将输出:</P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >There are 4 columns in the result set.</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN81921" ></A ><H2 >参见</H2 ><P > <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD ><A HREF="function.db2-execute.html" ><B CLASS="function" >db2_execute()</B ></A ></TD ></TR ><TR ><TD ><A HREF="function.db2-field-display-size.html" ><B CLASS="function" >db2_field_display_size()</B ></A ></TD ></TR ><TR ><TD ><A HREF="function.db2-field-name.html" ><B CLASS="function" >db2_field_name()</B ></A ></TD ></TR ><TR ><TD ><A HREF="function.db2-field-num.html" ><B CLASS="function" >db2_field_num()</B ></A ></TD ></TR ><TR ><TD ><A HREF="function.db2-field-precision.html" ><B CLASS="function" >db2_field_precision()</B ></A ></TD ></TR ><TR ><TD ><A HREF="function.db2-field-scale.html" ><B CLASS="function" >db2_field_scale()</B ></A ></TD ></TR ><TR ><TD ><A HREF="function.db2-field-type.html" ><B CLASS="function" >db2_field_type()</B ></A ></TD ></TR ><TR ><TD ><A HREF="function.db2-field-width.html" ><B CLASS="function" >db2_field_width()</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.db2-next-result.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.db2-num-rows.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >db2_next_result</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.ibm-db2.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >db2_num_rows</TD ></TR ></TABLE ></DIV ></BODY ></HTML >