<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.mongodb-driver-session.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'mongodb-driver-session.starttransaction.php',
    1 => 'MongoDB\\Driver\\Session::startTransaction',
    2 => 'Starts a transaction',
  ),
  'up' => 
  array (
    0 => 'class.mongodb-driver-session.php',
    1 => 'MongoDB\\Driver\\Session',
  ),
  'prev' => 
  array (
    0 => 'mongodb-driver-session.isintransaction.php',
    1 => 'MongoDB\\Driver\\Session::isInTransaction',
  ),
  'next' => 
  array (
    0 => 'class.mongodb-driver-clientencryption.php',
    1 => 'MongoDB\\Driver\\ClientEncryption',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/mongodb/mongodb/driver/session/starttransaction.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="mongodb-driver-session.starttransaction" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoDB\Driver\Session::startTransaction</h1>
  <p class="verinfo">(mongodb &gt;=1.5.0)</p><p class="refpurpose"><span class="refname">MongoDB\Driver\Session::startTransaction</span> &mdash; <span class="dc-title">Starts a transaction</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mongodb-driver-session.starttransaction-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><strong>MongoDB\Driver\Session::startTransaction</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.array.php" class="type array">array</a></span></span> <code class="parameter">$options</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>

  <p class="simpara">
   Starts a multi-document transaction associated with the session. At any given
   time, you can have at most one open transaction for a session. After starting
   a transaction, the session object must be passed to each operation via
   the <code class="literal">&quot;session&quot;</code> option (e.g.
   <span class="methodname"><a href="mongodb-driver-manager.executebulkwrite.php" class="methodname">MongoDB\Driver\Manager::executeBulkWrite()</a></span>) in order
   to associate that operation with the transaction.
  </p>
  <p class="simpara">
   Transactions can be committed through
   <span class="methodname"><a href="mongodb-driver-session.committransaction.php" class="methodname">MongoDB\Driver\Session::commitTransaction()</a></span>, and
   aborted with
   <span class="methodname"><a href="mongodb-driver-session.aborttransaction.php" class="methodname">MongoDB\Driver\Session::abortTransaction()</a></span>.
   Transactions are also automatically aborted when the session is closed from
   garbage collection or by explicitly calling
   <span class="methodname"><a href="mongodb-driver-session.endsession.php" class="methodname">MongoDB\Driver\Session::endSession()</a></span>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-mongodb-driver-session.starttransaction-parameters">
  <h3 class="title">Parameters</h3>
  <dl>
   
    <dt><code class="parameter">options</code></dt>
    <dd>
     <span class="simpara">
      Options can be passed as argument to this method. Each element in this
      options array overrides the corresponding option from the
      <code class="literal">&quot;defaultTransactionOptions&quot;</code> option, if set when
      starting the session with
      <span class="methodname"><a href="mongodb-driver-manager.startsession.php" class="methodname">MongoDB\Driver\Manager::startSession()</a></span>.
     </span>
     <p class="para">
      <table class="doctable table">
       <caption><strong>options</strong></caption>
       
        <thead>
         <tr>
          <th>Option</th>
          <th>Type</th>
          <th>Description</th>
         </tr>

        </thead>

        <tbody class="tbody">
         
         <tr>
          <td>maxCommitTimeMS</td>
          <td>integer</td>
          <td>
           <p class="para">
            The maximum amount of time in milliseconds to allow a single
            <code class="literal">commitTransaction</code> command to run.
           </p>
           <p class="para">
            If specified, <code class="literal">maxCommitTimeMS</code> must be a signed
            32-bit integer greater than or equal to zero.
           </p>
          </td>
         </tr>


         
         <tr>
          <td>readConcern</td>
          <td><span class="classname"><a href="class.mongodb-driver-readconcern.php" class="classname">MongoDB\Driver\ReadConcern</a></span></td>
          <td>
           <p class="para">
            A read concern to apply to the operation.
           </p>
           <p class="para">
            This option is available in MongoDB 3.2+ and will result in an
            exception at execution time if specified for an older server
            version.
           </p>
          </td>
         </tr>


         
         <tr>
          <td>readPreference</td>
          <td><span class="classname"><a href="class.mongodb-driver-readpreference.php" class="classname">MongoDB\Driver\ReadPreference</a></span></td>
          <td>
           <p class="para">
            A read preference to use for selecting a server for the operation.
           </p>
          </td>
         </tr>


         
         <tr>
          <td>writeConcern</td>
          <td><span class="classname"><a href="class.mongodb-driver-writeconcern.php" class="classname">MongoDB\Driver\WriteConcern</a></span></td>
          <td>
           <p class="para">
            A write concern to apply to the operation.
           </p>
          </td>
         </tr>


        </tbody>
       
      </table>

     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mongodb-driver-session.starttransaction-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="simpara">
   No value is returned.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-mongodb-driver-session.starttransaction-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <ul class="simplelist">
   <li>Throws <span class="classname"><a href="class.mongodb-driver-exception-invalidargumentexception.php" class="classname">MongoDB\Driver\Exception\InvalidArgumentException</a></span> on argument parsing errors.</li>
   <li>Throws <span class="classname"><a href="class.mongodb-driver-exception-commandexception.php" class="classname">MongoDB\Driver\Exception\CommandException</a></span> if the transaction could not be started because of a server-side problem (e.g. a lock could not be obtained).</li>
   <li>Throws <span class="classname"><a href="class.mongodb-driver-exception-runtimeexception.php" class="classname">MongoDB\Driver\Exception\RuntimeException</a></span> if the transaction could not be started (e.g. a transaction was already started).</li>
  </ul>
 </div>


 <div class="refsect1 changelog" id="refsect1-mongodb-driver-session.starttransaction-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>PECL mongodb 1.6.0</td>
      <td>
       <span class="simpara">
        The <code class="literal">&quot;maxCommitTimeMS&quot;</code> option was added.
       </span>
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 seealso" id="refsect1-mongodb-driver-session.starttransaction-seealso">
  <h3 class="title">See Also</h3>
  <ul class="simplelist">
   <li><span class="methodname"><a href="mongodb-driver-manager.startsession.php" class="methodname" rel="rdfs-seeAlso">MongoDB\Driver\Manager::startSession()</a> - Start a new client session for use with this client</span></li>
   <li><span class="methodname"><a href="mongodb-driver-session.committransaction.php" class="methodname" rel="rdfs-seeAlso">MongoDB\Driver\Session::commitTransaction()</a> - Commits a transaction</span></li>
   <li><span class="methodname"><a href="mongodb-driver-session.aborttransaction.php" class="methodname" rel="rdfs-seeAlso">MongoDB\Driver\Session::abortTransaction()</a> - Aborts a transaction</span></li>
  </ul>
 </div>


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