Sophie

Sophie

distrib > Mageia > 4 > i586 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 10177

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Initiates a transaction</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="class.pdo.html">PDO</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="pdo.commit.html">PDO::commit</a></div>
 <div class="up"><a href="class.pdo.html">PDO</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="pdo.begintransaction" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">PDO::beginTransaction</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, PECL pdo &gt;= 0.1.0)</p><p class="refpurpose"><span class="refname">PDO::beginTransaction</span> &mdash; <span class="dc-title">
   Initiates a transaction
  </span></p>

 </div>

 <div class="refsect1 description" id="refsect1-pdo.begintransaction-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">bool</span> <span class="methodname"><strong>PDO::beginTransaction</strong></span>
    ( <span class="methodparam">void</span>
   )</div>

  <p class="para rdfs-comment">
   Turns off autocommit mode.  While autocommit mode is turned off, changes
   made to the database via the PDO object instance are not committed until
   you end the transaction by calling  <span class="function"><a href="pdo.commit.html" class="function">PDO::commit()</a></span>.
   Calling  <span class="function"><a href="pdo.rollback.html" class="function">PDO::rollBack()</a></span> will roll back all changes to
   the database and return the connection to autocommit mode.
  </p>
  <p class="para">
   Some databases, including MySQL, automatically issue an implicit
   COMMIT when a database definition language (DDL) statement such as
   DROP TABLE or CREATE TABLE is issued within a transaction. The implicit
   COMMIT will prevent you from rolling back any other changes within the
   transaction boundary.
  </p>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-pdo.begintransaction-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-pdo.begintransaction-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-915"><p><strong>Example #1 Roll back a transaction</strong></p>
    <div class="example-contents"><p>
     The following example begins a transaction and issues two statements
     that modify the database before rolling back the changes. On MySQL,
     however, the DROP TABLE statement automatically commits the
     transaction so that none of the changes in the transaction are rolled
     back.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Begin&nbsp;a&nbsp;transaction,&nbsp;turning&nbsp;off&nbsp;autocommit&nbsp;*/<br /></span><span style="color: #0000BB">$dbh</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">beginTransaction</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/*&nbsp;Change&nbsp;the&nbsp;database&nbsp;schema&nbsp;and&nbsp;data&nbsp;*/<br /></span><span style="color: #0000BB">$sth&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$dbh</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">"DROP&nbsp;TABLE&nbsp;fruit"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$sth&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$dbh</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">"UPDATE&nbsp;dessert<br />&nbsp;&nbsp;&nbsp;&nbsp;SET&nbsp;name&nbsp;=&nbsp;'hamburger'"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Recognize&nbsp;mistake&nbsp;and&nbsp;roll&nbsp;back&nbsp;changes&nbsp;*/<br /></span><span style="color: #0000BB">$dbh</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">rollBack</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/*&nbsp;Database&nbsp;connection&nbsp;is&nbsp;now&nbsp;back&nbsp;in&nbsp;autocommit&nbsp;mode&nbsp;*/<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-pdo.begintransaction-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="function"><a href="pdo.commit.html" class="function" rel="rdfs-seeAlso">PDO::commit()</a> - Commits a transaction</span></li>
    <li class="member"> <span class="function"><a href="pdo.rollback.html" class="function" rel="rdfs-seeAlso">PDO::rollBack()</a> - Rolls back a transaction</span></li>
    <li class="member"><a href="pdo.transactions.html" class="link">Transactions and auto-commit</a></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="class.pdo.html">PDO</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="pdo.commit.html">PDO::commit</a></div>
 <div class="up"><a href="class.pdo.html">PDO</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>