<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.pdo.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'pdo.begintransaction.php',
    1 => 'PDO::beginTransaction',
    2 => 'Initiates a transaction',
  ),
  'up' => 
  array (
    0 => 'class.pdo.php',
    1 => 'PDO',
  ),
  'prev' => 
  array (
    0 => 'class.pdo.php',
    1 => 'PDO',
  ),
  'next' => 
  array (
    0 => 'pdo.commit.php',
    1 => 'PDO::commit',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/pdo/pdo/begintransaction.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="pdo.begintransaction" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">PDO::beginTransaction</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7, PHP 8, 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">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>PDO::beginTransaction</strong></span>(): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></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="methodname"><a href="pdo.commit.php" class="methodname">PDO::commit()</a></span>.
   Calling <span class="methodname"><a href="pdo.rollback.php" class="methodname">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 parameters" id="refsect1-pdo.begintransaction-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">У цієї функції немає
параметрів.</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-pdo.begintransaction-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   Повертає <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> у разі успіху або <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> в разі помилки.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-pdo.begintransaction-errors">
  <h3 class="title">Помилки/виключення</h3>
  <p class="para">
   Throws a <span class="classname"><a href="class.pdoexception.php" class="classname">PDOException</a></span> if there is already a transaction started or the driver does not support transactions.
  </p>
  <blockquote class="note"><p><strong class="note">Зауваження</strong>: <span class="simpara">Виключення викидається
навіть якщо атрибут <strong><code><a href="pdo.constants.php#pdo.constants.attr-errmode">PDO::ATTR_ERRMODE</a></code></strong> не є
<strong><code><a href="pdo.constants.php#pdo.constants.errmode-exception">PDO::ERRMODE_EXCEPTION</a></code></strong>.</span></p></blockquote>
 </div>


 <div class="refsect1 examples" id="refsect1-pdo.begintransaction-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1"><p><strong>Приклад #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">/* Begin a transaction, turning off autocommit */<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">/* Change the database schema and data */<br /></span><span style="color: #0000BB">$sth </span><span style="color: #007700">= </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 TABLE fruit"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$sth </span><span style="color: #007700">= </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 dessert<br />    SET name = 'hamburger'"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Recognize mistake and roll back changes */<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">/* Database connection is now back in autocommit mode */<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">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="pdo.commit.php" class="methodname" rel="rdfs-seeAlso">PDO::commit()</a> - Commits a transaction</span></li>
    <li><span class="methodname"><a href="pdo.rollback.php" class="methodname" rel="rdfs-seeAlso">PDO::rollBack()</a> - Rolls back a transaction</span></li>
    <li><a href="pdo.transactions.php" class="link">Transactions and auto-commit</a></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>