Sophie

Sophie

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

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
>PDO-&#62;exec()</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->errorInfo()"
HREF="function.pdo-errorinfo.html"><LINK
REL="NEXT"
TITLE="PDO->getAttribute()"
HREF="function.pdo-getattribute.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-errorinfo.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.pdo-getattribute.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.PDO-exec"
></A
>PDO-&#62;exec()</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN176552"
></A
><P
>    (no version information, might be only in CVS)</P
>PDO-&#62;exec()&nbsp;--&nbsp;
   Execute an SQL statement and return the number of affected rows
  </DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN176555"
></A
><H2
>说明</H2
>class <B
CLASS="classname"
>PDO</B
> { <BR
></BR
>int <B
CLASS="methodname"
>exec</B
> ( string statement )<BR
></BR
>}<P
>&#13;   <A
HREF="function.pdo-exec.html"
>PDO-&#62;exec()</A
> executes an SQL statement in
   a single function call, returning the number of rows affected by the
   statement.
  </P
><P
>&#13;   <A
HREF="function.pdo-exec.html"
>PDO-&#62;exec()</A
> does not return results from a SELECT
   statement. For a SELECT statement that you only need to issue once
   during your program, consider issuing <A
HREF="function.pdo-query.html"
>PDO-&#62;query()</A
>.
   For a statement that you need to issue multiple times, prepare 
   a PDOStatement object with <A
HREF="function.pdo-prepare.html"
>PDO-&#62;prepare()</A
> and issue
   the statement with <A
HREF="function.pdostatement-execute.html"
>PDOStatement-&#62;execute()</A
>.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN176573"
></A
><H2
>参数</H2
><P
>&#13;   <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><CODE
CLASS="parameter"
>statement</CODE
></DT
><DD
><P
>&#13;        The SQL statement to prepare and execute.
       </P
></DD
></DL
></DIV
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN176582"
></A
><H2
>返回值</H2
><P
>&#13;   <A
HREF="function.pdo-exec.html"
>PDO-&#62;exec()</A
> returns the number of rows that were modified
   or deleted by the SQL statement you issued. If no rows were affected, 
   <A
HREF="function.pdo-exec.html"
>PDO-&#62;exec()</A
> returns <TT
CLASS="literal"
>0</TT
>. 
  </P
><DIV
CLASS="warning"
><P
></P
><TABLE
CLASS="warning"
BORDER="1"
WIDTH="100%"
><TR
><TD
ALIGN="CENTER"
><B
>警告</B
></TD
></TR
><TR
><TD
ALIGN="LEFT"
><P
>本函数可能返回布尔值
<TT
CLASS="constant"
><B
>FALSE</B
></TT
>,但也可能返回一个与 <TT
CLASS="constant"
><B
>FALSE</B
></TT
> 等值的非布尔值,例如
<TT
CLASS="literal"
>0</TT
> 或者 ""。请参阅<A
HREF="language.types.boolean.html"
>布尔类型</A
>章节以获取更多信息。应使用
<A
HREF="language.operators.comparison.html"
>=== 运算符</A
>来测试本函数的返回值。</P
></TD
></TR
></TABLE
></DIV
><P
>&#13;   The following example incorrectly relies on the return value of
   <A
HREF="function.pdo-exec.html"
>PDO-&#62;exec()</A
>, wherein a statement that affected 0 rows
   results in a call to <A
HREF="function.die.html"
><B
CLASS="function"
>die()</B
></A
>:
   <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />$db</font><font color="#007700">-&gt;</font><font color="#0000BB">exec</font><font color="#007700">() or die(</font><font color="#0000BB">$db</font><font color="#007700">-&gt;</font><font color="#0000BB">errorInfo</font><font color="#007700">());<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN176599"
></A
><H2
>范例</H2
><P
>&#13;   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN176602"
></A
><P
><B
>例 1. Issuing a DELETE statement</B
></P
><P
>&#13;     Count the number of rows deleted by a DELETE statement with no WHERE
     clause.
    </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />$dbh </font><font color="#007700">= new </font><font color="#0000BB">PDO</font><font color="#007700">(</font><font color="#DD0000">'odbc:sample'</font><font color="#007700">, </font><font color="#DD0000">'db2inst1'</font><font color="#007700">, </font><font color="#DD0000">'ibmdb2'</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Delete all rows from the FRUIT table */<br /></font><font color="#0000BB">$count </font><font color="#007700">= </font><font color="#0000BB">$dbh</font><font color="#007700">-&gt;</font><font color="#0000BB">exec</font><font color="#007700">(</font><font color="#DD0000">"DELETE FROM fruit WHERE colour = 'red'"</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Return number of rows that were deleted */<br /></font><font color="#007700">print(</font><font color="#DD0000">"Deleted $count rows.</font><font color="#007700">\n</font><font color="#DD0000">"</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"
>Deleted 1 rows.</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN176608"
></A
><H2
>参见</H2
><P
>&#13;   <P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
><A
HREF="function.pdo-prepare.html"
>PDO-&#62;prepare()</A
></TD
></TR
><TR
><TD
><A
HREF="function.pdo-query.html"
>PDO-&#62;query()</A
></TD
></TR
><TR
><TD
><A
HREF="function.pdostatement-execute.html"
>PDOStatement-&#62;execute()</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-errorinfo.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.pdo-getattribute.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>PDO-&#62;errorInfo()</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.pdo.html"
ACCESSKEY="U"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>PDO-&#62;getAttribute()</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>