<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >db2_rollback</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_result" HREF="function.db2-result.html"><LINK REL="NEXT" TITLE="db2_server_info" HREF="function.db2-server-info.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-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-server-info.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.db2-rollback" ></A >db2_rollback</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN82625" ></A ><P > (PECL)</P >db2_rollback -- Rolls back a transaction </DIV ><DIV CLASS="refsect1" ><A NAME="AEN82628" ></A ><H2 >说明</H2 >bool <B CLASS="methodname" >db2_rollback</B > ( resource connection )<BR ></BR ><P > Rolls back an in-progress transaction on the specified connection resource and begins a new transaction. PHP applications normally default to AUTOCOMMIT mode, so <B CLASS="function" >db2_rollback()</B > normally has no effect unless AUTOCOMMIT has been turned off for the connection resource. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B > If the specified connection resource is a persistent connection, all transactions in progress for all applications using that persistent connection will be rolled back. For this reason, persistent connections are not recommended for use in applications that require transactions. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN82640" ></A ><H2 >参数</H2 ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >connection</CODE ></DT ><DD ><P > A valid database connection resource variable as returned from <A HREF="function.db2-connect.html" ><B CLASS="function" >db2_connect()</B ></A > or <A HREF="function.db2-pconnect.html" ><B CLASS="function" >db2_pconnect()</B ></A >. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN82651" ></A ><H2 >返回值</H2 ><P > 如果成功则返回 <TT CLASS="constant" ><B >TRUE</B ></TT >,失败则返回 <TT CLASS="constant" ><B >FALSE</B ></TT >。 </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN82656" ></A ><H2 >范例</H2 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN82659" ></A ><P ><B >例 1. Rolling back a DELETE statement</B ></P ><P > In the following example, we count the number of rows in a table, turn off AUTOCOMMIT mode on a database connection, delete all of the rows in the table and return the count of <TT CLASS="literal" >0</TT > to prove that the rows have been removed. We then issue <B CLASS="function" >db2_rollback()</B > and return the updated count of rows in the table to show that the number is the same as before we issued the DELETE statement. The return to the original state of the table demonstrates that the roll back of the transaction succeeded. </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$conn </font><font color="#007700">= </font><font color="#0000BB">db2_connect</font><font color="#007700">(</font><font color="#0000BB">$database</font><font color="#007700">, </font><font color="#0000BB">$user</font><font color="#007700">, </font><font color="#0000BB">$password</font><font color="#007700">);<br /><br />if (</font><font color="#0000BB">$conn</font><font color="#007700">) {<br /> </font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">db2_exec</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#DD0000">"SELECT count(*) FROM animals"</font><font color="#007700">);<br /> </font><font color="#0000BB">$res </font><font color="#007700">= </font><font color="#0000BB">db2_fetch_array</font><font color="#007700">( </font><font color="#0000BB">$stmt </font><font color="#007700">);<br /> echo </font><font color="#0000BB">$res</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">] . </font><font color="#DD0000">"\n"</font><font color="#007700">;<br /> <br /> </font><font color="#FF8000">// Turn AUTOCOMMIT off<br /> </font><font color="#0000BB">db2_autocommit</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#0000BB">DB2_AUTOCOMMIT_OFF</font><font color="#007700">);<br /> <br /> </font><font color="#FF8000">// Delete all rows from ANIMALS<br /> </font><font color="#0000BB">db2_exec</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#DD0000">"DELETE FROM animals"</font><font color="#007700">);<br /> <br /> </font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">db2_exec</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#DD0000">"SELECT count(*) FROM animals"</font><font color="#007700">);<br /> </font><font color="#0000BB">$res </font><font color="#007700">= </font><font color="#0000BB">db2_fetch_array</font><font color="#007700">( </font><font color="#0000BB">$stmt </font><font color="#007700">);<br /> echo </font><font color="#0000BB">$res</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">] . </font><font color="#DD0000">"\n"</font><font color="#007700">;<br /> <br /> </font><font color="#FF8000">// Roll back the DELETE statement<br /> </font><font color="#0000BB">db2_rollback</font><font color="#007700">( </font><font color="#0000BB">$conn </font><font color="#007700">);<br /> <br /> </font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">db2_exec</font><font color="#007700">( </font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#DD0000">"SELECT count(*) FROM animals" </font><font color="#007700">);<br /> </font><font color="#0000BB">$res </font><font color="#007700">= </font><font color="#0000BB">db2_fetch_array</font><font color="#007700">( </font><font color="#0000BB">$stmt </font><font color="#007700">);<br /> echo </font><font color="#0000BB">$res</font><font color="#007700">[</font><font color="#0000BB">0</font><font color="#007700">] . </font><font color="#DD0000">"\n"</font><font color="#007700">;<br /> </font><font color="#0000BB">db2_close</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">);<br />}<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" >7 0 7</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN82667" ></A ><H2 >参见</H2 ><P > <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD ><A HREF="function.db2-autocommit.html" ><B CLASS="function" >db2_autocommit()</B ></A ></TD ></TR ><TR ><TD ><A HREF="function.db2-commit.html" ><B CLASS="function" >db2_commit()</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-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-server-info.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >db2_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_server_info</TD ></TR ></TABLE ></DIV ></BODY ></HTML >