<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.oci8.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.oci-execute.php',
    1 => 'oci_execute',
    2 => 'Executes a statement',
  ),
  'up' => 
  array (
    0 => 'ref.oci8.php',
    1 => 'OCI8 Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.oci-error.php',
    1 => 'oci_error',
  ),
  'next' => 
  array (
    0 => 'function.oci-fetch.php',
    1 => 'oci_fetch',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/oci8/functions/oci-execute.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.oci-execute" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">oci_execute</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8, PECL OCI8 &gt;= 1.1.0)</p><p class="refpurpose"><span class="refname">oci_execute</span> &mdash; <span class="dc-title">Executes a statement</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.oci-execute-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>oci_execute</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> <code class="parameter">$statement</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$mode</code><span class="initializer"> = <strong><code><a href="oci8.constants.php#constant.oci-commit-on-success">OCI_COMMIT_ON_SUCCESS</a></code></strong></span></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   Executes a <code class="parameter">statement</code> previously returned
   from <span class="function"><a href="function.oci-parse.php" class="function">oci_parse()</a></span>.
  </p>
  <p class="para">
   After execution, statements like <code class="literal">INSERT</code> will
   have data committed to the database by default.  For statements
   like <code class="literal">SELECT</code>, execution performs the logic of the
   query. Query results can subsequently be fetched in PHP with
   functions like <span class="function"><a href="function.oci-fetch-array.php" class="function">oci_fetch_array()</a></span>.
  </p>
  <p class="para">
   Each parsed statement may be executed multiple times, saving the
   cost of re-parsing.  This is commonly used
   for <code class="literal">INSERT</code> statements when data is bound
   with <span class="function"><a href="function.oci-bind-by-name.php" class="function">oci_bind_by_name()</a></span>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.oci-execute-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">statement</code></dt>
     <dd>
      <p class="para">
       A valid OCI statement identifier.
      </p>
     </dd>
    
    
     <dt><code class="parameter">mode</code></dt>
     <dd>
      <p class="para">
        An optional second parameter can be one of the following constants:
       <table class="doctable table">
        <caption><strong>Execution Modes</strong></caption>
        
         <thead>
          <tr>
           <th>Constant</th>
           <th>Description</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td><strong><code><a href="oci8.constants.php#constant.oci-commit-on-success">OCI_COMMIT_ON_SUCCESS</a></code></strong></td>
           <td>Automatically commit all outstanding changes for
             this connection when the statement has succeeded. This
             is the default.</td>
          </tr>

          <tr>
           <td><strong><code><a href="oci8.constants.php#constant.oci-describe-only">OCI_DESCRIBE_ONLY</a></code></strong></td>
           <td>Make query meta data available to functions
             like <span class="function"><a href="function.oci-field-name.php" class="function">oci_field_name()</a></span> but do not
             create a result set. Any subsequent fetch call such
             as <span class="function"><a href="function.oci-fetch-array.php" class="function">oci_fetch_array()</a></span> will
             fail.</td>
          </tr>

          <tr>
           <td><strong><code><a href="oci8.constants.php#constant.oci-no-auto-commit">OCI_NO_AUTO_COMMIT</a></code></strong></td>
           <td>Do not automatically commit changes.</td>
          </tr>

         </tbody>
        
       </table>

      </p>
      <p class="para">
       Using <strong><code><a href="oci8.constants.php#constant.oci-no-auto-commit">OCI_NO_AUTO_COMMIT</a></code></strong> mode starts or continues a
       transaction. Transactions are automatically rolled back when
       the connection is closed, or when the script ends.  Explicitly
       call <span class="function"><a href="function.oci-commit.php" class="function">oci_commit()</a></span> to commit a transaction,
       or <span class="function"><a href="function.oci-rollback.php" class="function">oci_rollback()</a></span> to abort it.
      </p>
      <p class="para">
       When inserting or updating data, using transactions is
       recommended for relational data consistency and for performance
       reasons.
      </p>
      <p class="para">
       If <strong><code><a href="oci8.constants.php#constant.oci-no-auto-commit">OCI_NO_AUTO_COMMIT</a></code></strong> mode is used for any
       statement including queries, and 
        <span class="function"><a href="function.oci-commit.php" class="function">oci_commit()</a></span>
       or <span class="function"><a href="function.oci-rollback.php" class="function">oci_rollback()</a></span> is not subsequently
       called, then OCI8 will perform a rollback at the end of the
       script even if no data was changed.  To avoid an unnecessary
       rollback, many scripts do not
       use <strong><code><a href="oci8.constants.php#constant.oci-no-auto-commit">OCI_NO_AUTO_COMMIT</a></code></strong> mode for queries or
       PL/SQL.  Be careful to ensure the appropriate transactional
       consistency for the application when
       using <span class="function"><strong>oci_execute()</strong></span> with different modes in
       the same script.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.oci-execute-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 examples" id="refsect1-function.oci-execute-examples">
  <h3 class="title">Esempi</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>oci_execute()</strong></span> for queries</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$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">'SELECT * FROM employees'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">oci_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #DD0000">"&lt;table border='1'&gt;\n"</span><span style="color: #007700">;<br />while (</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_fetch_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">, </span><span style="color: #0000BB">OCI_ASSOC</span><span style="color: #007700">+</span><span style="color: #0000BB">OCI_RETURN_NULLS</span><span style="color: #007700">)) {<br />    echo </span><span style="color: #DD0000">"&lt;tr&gt;\n"</span><span style="color: #007700">;<br />    foreach (</span><span style="color: #0000BB">$row </span><span style="color: #007700">as </span><span style="color: #0000BB">$item</span><span style="color: #007700">) {<br />        echo </span><span style="color: #DD0000">"    &lt;td&gt;" </span><span style="color: #007700">. (</span><span style="color: #0000BB">$item </span><span style="color: #007700">!== </span><span style="color: #0000BB">null </span><span style="color: #007700">? </span><span style="color: #0000BB">htmlentities</span><span style="color: #007700">(</span><span style="color: #0000BB">$item</span><span style="color: #007700">, </span><span style="color: #0000BB">ENT_QUOTES</span><span style="color: #007700">) : </span><span style="color: #DD0000">"&amp;nbsp;"</span><span style="color: #007700">) . </span><span style="color: #DD0000">"&lt;/td&gt;\n"</span><span style="color: #007700">;<br />    }<br />    echo </span><span style="color: #DD0000">"&lt;/tr&gt;\n"</span><span style="color: #007700">;<br />}<br />echo </span><span style="color: #DD0000">"&lt;/table&gt;\n"</span><span style="color: #007700">;<br /><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 <span class="function"><strong>oci_execute()</strong></span> without specifying a mode example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">// Before running, create the table:<br />//   CREATE TABLE MYTABLE (col1 NUMBER);<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 mytab (col1) VALUES (123)'</span><span style="color: #007700">);<br /><br /></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: #FF8000">// The row is committed and immediately visible to other users<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-3">
    <p><strong>Example #3 <span class="function"><strong>oci_execute()</strong></span> with <strong><code><a href="oci8.constants.php#constant.oci-no-auto-commit">OCI_NO_AUTO_COMMIT</a></code></strong> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">// Before running, create the table:<br />//   CREATE TABLE MYTABLE (col1 NUMBER);<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 mytab (col1) VALUES (:bv)'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">oci_bind_by_name</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">, </span><span style="color: #DD0000">':bv'</span><span style="color: #007700">, </span><span style="color: #0000BB">$i</span><span style="color: #007700">, </span><span style="color: #0000BB">10</span><span style="color: #007700">);<br />for (</span><span style="color: #0000BB">$i </span><span style="color: #007700">= </span><span style="color: #0000BB">1</span><span style="color: #007700">; </span><span style="color: #0000BB">$i </span><span style="color: #007700">&lt;= </span><span style="color: #0000BB">5</span><span style="color: #007700">; ++</span><span style="color: #0000BB">$i</span><span style="color: #007700">) {<br />    </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 />}<br /></span><span style="color: #0000BB">oci_commit</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);  </span><span style="color: #FF8000">// commits all new values: 1, 2, 3, 4, 5<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-4">
    <p><strong>Example #4 <span class="function"><strong>oci_execute()</strong></span> with different commit modes example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">// Before running, create the table:<br />//   CREATE TABLE MYTABLE (col1 NUMBER);<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 mytab (col1) VALUES (123)'</span><span style="color: #007700">);<br /></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">);  </span><span style="color: #FF8000">// data not committed<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 mytab (col1) VALUES (456)'</span><span style="color: #007700">);<br /></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: #FF8000">// commits both 123 and 456 values<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-5">
    <p><strong>Example #5 <span class="function"><strong>oci_execute()</strong></span> with
     <strong><code><a href="oci8.constants.php#constant.oci-describe-only">OCI_DESCRIBE_ONLY</a></code></strong> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$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">'SELECT * FROM locations'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">oci_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$s</span><span style="color: #007700">, </span><span style="color: #0000BB">OCI_DESCRIBE_ONLY</span><span style="color: #007700">);<br />for (</span><span style="color: #0000BB">$i </span><span style="color: #007700">= </span><span style="color: #0000BB">1</span><span style="color: #007700">; </span><span style="color: #0000BB">$i </span><span style="color: #007700">&lt;= </span><span style="color: #0000BB">oci_num_fields</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">); ++</span><span style="color: #0000BB">$i</span><span style="color: #007700">) {<br />    echo </span><span style="color: #0000BB">oci_field_name</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">, </span><span style="color: #0000BB">$i</span><span style="color: #007700">) . </span><span style="color: #DD0000">"&lt;br&gt;\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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


 <div class="refsect1 notes" id="refsect1-function.oci-execute-notes">
  <h3 class="title">Note</h3>
  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <p class="para">
    Transactions are automatically rolled back when connections are
    closed, or when the script ends, whichever is soonest.  Explicitly
    call <span class="function"><a href="function.oci-commit.php" class="function">oci_commit()</a></span> to commit a transaction.
   </p>
   <p class="para">
    Any call to <span class="function"><strong>oci_execute()</strong></span> that uses
    <strong><code><a href="oci8.constants.php#constant.oci-commit-on-success">OCI_COMMIT_ON_SUCCESS</a></code></strong> mode explicitly or by
    default will commit any previous uncommitted transaction.
   </p>
   <p class="para">
    Any Oracle DDL statement such as <code class="literal">CREATE</code>
    or <code class="literal">DROP</code> will automatically commit any
    uncommitted transaction.
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <p class="para">
    Because the <span class="function"><strong>oci_execute()</strong></span> function generally
    sends the statement to the
    database, <span class="function"><strong>oci_execute()</strong></span> can identify some
    statement syntax errors that the lightweight,
    local <span class="function"><a href="function.oci-parse.php" class="function">oci_parse()</a></span> function does not.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.oci-execute-seealso">
  <h3 class="title">Vedere anche:</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.oci-parse.php" class="function" rel="rdfs-seeAlso">oci_parse()</a> - Prepares an Oracle statement for execution</span></li>
   </ul>
  </p>
 </div>


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