<?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 => 'it',
  ),
  'this' => 
  array (
    0 => 'pdo.commit.php',
    1 => 'PDO::commit',
    2 => 'Commits a transaction',
  ),
  'up' => 
  array (
    0 => 'class.pdo.php',
    1 => 'PDO',
  ),
  'prev' => 
  array (
    0 => 'pdo.begintransaction.php',
    1 => 'PDO::beginTransaction',
  ),
  'next' => 
  array (
    0 => 'pdo.connect.php',
    1 => 'PDO::connect',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/pdo/pdo/commit.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="pdo.commit" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">PDO::commit</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::commit</span> &mdash; <span class="dc-title">
   Commits a transaction
  </span></p>

 </div>

 <div class="refsect1 description" id="refsect1-pdo.commit-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>PDO::commit</strong></span>(): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   Commits a transaction, returning the database connection to autocommit
   mode until the next call to <span class="methodname"><a href="pdo.begintransaction.php" class="methodname">PDO::beginTransaction()</a></span>
   starts a new transaction.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-pdo.commit-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <p class="para">Questa funzione non contiene parametri.</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-pdo.commit-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">
   Restituisce <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> in caso di successo, <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> in caso di fallimento.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-pdo.commit-errors">
  <h3 class="title">Errori/Eccezioni</h3>
  <p class="para">
   Throws a <span class="classname"><a href="class.pdoexception.php" class="classname">PDOException</a></span> if there is no active transaction.
  </p>
  <blockquote class="note"><p><strong class="note">Nota</strong>: <span class="simpara">An exception is raised even when the <strong><code><a href="pdo.constants.php#pdo.constants.attr-errmode">PDO::ATTR_ERRMODE</a></code></strong> attribute is not <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.commit-examples">
  <h3 class="title">Esempi</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 Committing a basic transaction</strong></p>
    <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">/* Insert multiple records on an all-or-nothing basis */<br /></span><span style="color: #0000BB">$sql </span><span style="color: #007700">= </span><span style="color: #DD0000">'INSERT INTO fruit<br />    (name, colour, calories)<br />    VALUES (?, ?, ?)'</span><span style="color: #007700">;<br /><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">prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$sql</span><span style="color: #007700">);<br /><br />foreach (</span><span style="color: #0000BB">$fruits </span><span style="color: #007700">as </span><span style="color: #0000BB">$fruit</span><span style="color: #007700">) {<br />    </span><span style="color: #0000BB">$sth</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">execute</span><span style="color: #007700">(array(<br />        </span><span style="color: #0000BB">$fruit</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">name</span><span style="color: #007700">,<br />        </span><span style="color: #0000BB">$fruit</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">colour</span><span style="color: #007700">,<br />        </span><span style="color: #0000BB">$fruit</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">calories</span><span style="color: #007700">,<br />    ));<br />}<br /><br /></span><span style="color: #FF8000">/* Commit the changes */<br /></span><span style="color: #0000BB">$dbh</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">commit</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>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Example #2 Committing a DDL transaction</strong></p>
    <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 */<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 /><br /></span><span style="color: #FF8000">/* Commit the changes */<br /></span><span style="color: #0000BB">$dbh</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">commit</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>
   <blockquote class="note"><p><strong class="note">Nota</strong>: 
    <span class="simpara">
     Not all databases will allow transactions to operate on DDL statements:
     some will generate errors, whereas others (including MySQL) will
     automatically commit the transaction after the first DDL statement has
     been encountered.
    </span>
   </p></blockquote>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-pdo.commit-seealso">
  <h3 class="title">Vedere anche:</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="pdo.begintransaction.php" class="methodname" rel="rdfs-seeAlso">PDO::beginTransaction()</a> - Initiates 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); ?>