<!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>Commits the outstanding database transaction</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.oci-close.html">oci_close</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.oci-connect.html">oci_connect</a></div> <div class="up"><a href="ref.oci8.html">OCI8 Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.oci-commit" class="refentry"> <div class="refnamediv"> <h1 class="refname">oci_commit</h1> <p class="verinfo">(PHP 5, PECL OCI8 >= 1.1.0)</p><p class="refpurpose"><span class="refname">oci_commit</span> — <span class="dc-title">Commits the outstanding database transaction</span></p> </div> <div class="refsect1 description" id="refsect1-function.oci-commit-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><strong>oci_commit</strong></span> ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$connection</code></span> )</div> <p class="para rdfs-comment"> Commits the outstanding transaction for the Oracle <em><code class="parameter">connection</code></em>. A commit ends the current transaction and makes permanent all changes. It releases all locks held. </p> <p class="para"> A transaction begins when the first SQL statement that changes data is executed with <span class="function"><a href="function.oci-execute.html" class="function">oci_execute()</a></span> using the <strong><code>OCI_NO_AUTO_COMMIT</code></strong> flag. Further data changes made by other statements become part of the same transaction. Data changes made in a transaction are temporary until the transaction is committed or rolled back. Other users of the database will not see the changes until they are committed. </p> <p class="para"> When inserting or updating data, using transactions is recommended for relational data consistency and for performance reasons. </p> </div> <div class="refsect1 parameters" id="refsect1-function.oci-commit-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">connection</code></em></span> <dd> <p class="para"> An Oracle connection identifier, returned by <span class="function"><a href="function.oci-connect.html" class="function">oci_connect()</a></span>, <span class="function"><a href="function.oci-pconnect.html" class="function">oci_pconnect()</a></span>, or <span class="function"><a href="function.oci-new-connect.html" class="function">oci_new_connect()</a></span>. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.oci-commit-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-function.oci-commit-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-1961"> <p><strong>Example #1 <span class="function"><strong>oci_commit()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /><br /></span><span style="color: #FF8000">// Insert into several tables, rolling back the changes if an error occurs<br /><br /></span><span style="color: #0000BB">$conn </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'hr'</span><span style="color: #007700">, </span><span style="color: #DD0000">'welcome'</span><span style="color: #007700">, </span><span style="color: #DD0000">'localhost/XE'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$stid </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_parse</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">, </span><span style="color: #DD0000">"INSERT INTO mysalary (id, name) VALUES (1, 'Chris')"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// The OCI_NO_AUTO_COMMIT flag tells Oracle not to commit the INSERT immediately<br />// Use OCI_DEFAULT as the flag for PHP <= 5.3.1. The two flags are equivalent<br /></span><span style="color: #0000BB">$r </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">, </span><span style="color: #0000BB">OCI_NO_AUTO_COMMIT</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$r</span><span style="color: #007700">) { <br /> </span><span style="color: #0000BB">$e </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_error</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">trigger_error</span><span style="color: #007700">(</span><span style="color: #0000BB">htmlentities</span><span style="color: #007700">(</span><span style="color: #0000BB">$e</span><span style="color: #007700">[</span><span style="color: #DD0000">'message'</span><span style="color: #007700">]), </span><span style="color: #0000BB">E_USER_ERROR</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">$stid </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_parse</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">, </span><span style="color: #DD0000">'INSERT INTO myschedule (startday) VALUES (12)'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$r </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">, </span><span style="color: #0000BB">OCI_NO_AUTO_COMMIT</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$r</span><span style="color: #007700">) { <br /> </span><span style="color: #0000BB">$e </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_error</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">oci_rollback</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">); </span><span style="color: #FF8000">// rollback changes to both tables<br /> </span><span style="color: #0000BB">trigger_error</span><span style="color: #007700">(</span><span style="color: #0000BB">htmlentities</span><span style="color: #007700">(</span><span style="color: #0000BB">$e</span><span style="color: #007700">[</span><span style="color: #DD0000">'message'</span><span style="color: #007700">]), </span><span style="color: #0000BB">E_USER_ERROR</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #FF8000">// Commit the changes to both tables<br /></span><span style="color: #0000BB">$r </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_commit</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">r</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">$e </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_error</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">trigger_error</span><span style="color: #007700">(</span><span style="color: #0000BB">htmlentities</span><span style="color: #007700">(</span><span style="color: #0000BB">$e</span><span style="color: #007700">[</span><span style="color: #DD0000">'message'</span><span style="color: #007700">]), </span><span style="color: #0000BB">E_USER_ERROR</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 notes" id="refsect1-function.oci-commit-notes"> <h3 class="title">Notes</h3> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> Transactions are automatically rolled back when you close the connection, or when the script ends, whichever is soonest. You need to explicitly call <span class="function"><strong>oci_commit()</strong></span> to commit the transaction. </p> <p class="para"> Any call to <span class="function"><a href="function.oci-execute.html" class="function">oci_execute()</a></span> that uses <strong><code>OCI_COMMIT_ON_SUCCESS</code></strong> mode explicitly or by default will commit any previous uncommitted transaction. </p> <p class="para"> Any Oracle DDL statement such as <em>CREATE</em> or <em>DROP</em> will automatically commit any uncommitted transaction. </p> </p></blockquote> </div> <div class="refsect1 seealso" id="refsect1-function.oci-commit-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.oci-execute.html" class="function" rel="rdfs-seeAlso">oci_execute()</a> - Executes a statement</span></li> <li class="member"> <span class="function"><a href="function.oci-rollback.html" class="function" rel="rdfs-seeAlso">oci_rollback()</a> - Rolls back the outstanding database transaction</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.oci-close.html">oci_close</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.oci-connect.html">oci_connect</a></div> <div class="up"><a href="ref.oci8.html">OCI8 Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>