Sophie

Sophie

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

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
>PDOStatement-&#62;bindColumn()</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="PHP 手册"
HREF="index.html"><LINK
REL="UP"
TITLE="PDO Functions"
HREF="ref.pdo.html"><LINK
REL="PREVIOUS"
TITLE="PDO->setAttribute()"
HREF="function.pdo-setattribute.html"><LINK
REL="NEXT"
TITLE="PDOStatement->bindParam()"
HREF="function.pdostatement-bindparam.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.pdo-setattribute.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.pdostatement-bindparam.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.PDOStatement-bindColumn"
></A
>PDOStatement-&#62;bindColumn()</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN177123"
></A
><P
>    (no version information, might be only in CVS)</P
>PDOStatement-&#62;bindColumn()&nbsp;--&nbsp;
   Bind a column to a PHP variable
  </DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN177126"
></A
><H2
>说明</H2
>class <B
CLASS="classname"
>PDOStatement</B
> { <BR
></BR
>bool <B
CLASS="methodname"
>bindColumn</B
> ( mixed column, mixed &#38;param [, int type] )<BR
></BR
>}<P
>&#13;   <A
HREF="function.pdostatement-bindcolumn.html"
>PDOStatement-&#62;bindColumn()</A
> arranges to have a
   particular variable bound to a given column in the result-set from a
   query.  Each call to <A
HREF="function.pdostatement-fetch.html"
>PDOStatement-&#62;fetch()</A
> or
   <A
HREF="function.pdostatement-fetchall.html"
>PDOStatement-&#62;fetchAll()</A
> will update all the variables
   that are bound to columns.
  </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>注意: </B
>
    Since information about the columns is not always available to PDO until
    the statement is executed, portable applications should call this
    function <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>after</I
></SPAN
> <A
HREF="function.pdostatement-execute.html"
>PDOStatement-&#62;execute()</A
>.
   </P
></BLOCKQUOTE
></DIV
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN177151"
></A
><H2
>参数</H2
><P
>&#13;   <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><CODE
CLASS="parameter"
>column</CODE
></DT
><DD
><P
>&#13;        Number of the column (1-indexed) or name of the column in the result set.
        If using the column name, be aware that the name should match the
        case of the column, as returned by the driver.
       </P
></DD
><DT
><CODE
CLASS="parameter"
>param</CODE
></DT
><DD
><P
>&#13;        Name of the PHP variable to which the column will be bound.
       </P
></DD
><DT
><CODE
CLASS="parameter"
>type</CODE
></DT
><DD
><P
>&#13;        Data type of the parameter, specified by the PDO::PARAM_* constants.
       </P
></DD
></DL
></DIV
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN177170"
></A
><H2
>返回值</H2
><P
>&#13;   如果成功则返回 <TT
CLASS="constant"
><B
>TRUE</B
></TT
>,失败则返回 <TT
CLASS="constant"
><B
>FALSE</B
></TT
>。
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN177175"
></A
><H2
>范例</H2
><P
>&#13;   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN177178"
></A
><P
><B
>例 1. Binding result set output to PHP variables</B
></P
><P
>&#13;     Binding columns in the result set to PHP variables is an effective
     way to make the data contained in each row immediately available to
     your application. The following example demonstrates how PDO allows
     you to bind and retrieve columns with a variety of options and with
     intelligent defaults.
    </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /></font><font color="#007700">function </font><font color="#0000BB">readData</font><font color="#007700">(</font><font color="#0000BB">$dbh</font><font color="#007700">) {<br />&nbsp;&nbsp;</font><font color="#0000BB">$sql </font><font color="#007700">= </font><font color="#DD0000">'SELECT name, colour, calories FROM fruit'</font><font color="#007700">;<br />&nbsp;&nbsp;</font><font color="#0000BB">try </font><font color="#007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">$dbh</font><font color="#007700">-&gt;</font><font color="#0000BB">prepare</font><font color="#007700">(</font><font color="#0000BB">$sql</font><font color="#007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$stmt</font><font color="#007700">-&gt;</font><font color="#0000BB">execute</font><font color="#007700">();<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">/* Bind by column number */<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$stmt</font><font color="#007700">-&gt;</font><font color="#0000BB">bindColumn</font><font color="#007700">(</font><font color="#0000BB">1</font><font color="#007700">, </font><font color="#0000BB">$name</font><font color="#007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$stmt</font><font color="#007700">-&gt;</font><font color="#0000BB">bindColumn</font><font color="#007700">(</font><font color="#0000BB">2</font><font color="#007700">, </font><font color="#0000BB">$colour</font><font color="#007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">/* Bind by column name */<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$stmt</font><font color="#007700">-&gt;</font><font color="#0000BB">bindColumn</font><font color="#007700">(</font><font color="#DD0000">'calories'</font><font color="#007700">, </font><font color="#0000BB">$cals</font><font color="#007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;while (</font><font color="#0000BB">$row </font><font color="#007700">= </font><font color="#0000BB">$stmt</font><font color="#007700">-&gt;</font><font color="#0000BB">fetch</font><font color="#007700">(</font><font color="#0000BB">PDO</font><font color="#007700">::</font><font color="#0000BB">FETCH_BOUND</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$data </font><font color="#007700">= </font><font color="#0000BB">$name </font><font color="#007700">. </font><font color="#DD0000">"\t" </font><font color="#007700">. </font><font color="#0000BB">$colour </font><font color="#007700">. </font><font color="#DD0000">"\t" </font><font color="#007700">. </font><font color="#0000BB">$cals </font><font color="#007700">. </font><font color="#DD0000">"\n"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print </font><font color="#0000BB">$data</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;</font><font color="#0000BB">catch </font><font color="#007700">(</font><font color="#0000BB">PDOException $e</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;print </font><font color="#0000BB">$e</font><font color="#007700">-&gt;</font><font color="#0000BB">getMessage</font><font color="#007700">();<br />&nbsp;&nbsp;}<br />}<br /></font><font color="#0000BB">readData</font><font color="#007700">(</font><font color="#0000BB">$dbh</font><font color="#007700">);<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>上例将输出:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>apple   red     150
banana  yellow  175
kiwi    green   75
orange  orange  150
mango   red     200
strawberry      red     25</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN177184"
></A
><H2
>参见</H2
><P
>&#13;   <P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
><A
HREF="function.pdostatement-execute.html"
>PDOStatement-&#62;execute()</A
></TD
></TR
><TR
><TD
><A
HREF="function.pdostatement-fetch.html"
>PDOStatement-&#62;fetch()</A
></TD
></TR
><TR
><TD
><A
HREF="function.pdostatement-fetchall.html"
>PDOStatement-&#62;fetchAll()</A
></TD
></TR
><TR
><TD
><A
HREF="function.pdostatement-fetchcolumn.html"
>PDOStatement-&#62;fetchColumn()</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.pdo-setattribute.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.pdostatement-bindparam.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>PDO-&#62;setAttribute()</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.pdo.html"
ACCESSKEY="U"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>PDOStatement-&#62;bindParam()</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>