<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.cubrid.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'function.cubrid-execute.php',
    1 => 'cubrid_execute',
    2 => 'Execute a prepared SQL statement',
  ),
  'up' => 
  array (
    0 => 'ref.cubrid.php',
    1 => 'Функції CUBRID',
  ),
  'prev' => 
  array (
    0 => 'function.cubrid-error-msg.php',
    1 => 'cubrid_error_msg',
  ),
  'next' => 
  array (
    0 => 'function.cubrid-fetch.php',
    1 => 'cubrid_fetch',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/cubrid/functions/cubrid-execute.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.cubrid-execute" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">cubrid_execute</h1>
  <p class="verinfo">(PECL CUBRID &gt;= 8.3.0)</p><p class="refpurpose"><span class="refname">cubrid_execute</span> &mdash; <span class="dc-title">Execute a prepared SQL statement</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.cubrid-execute-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>cubrid_execute</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> <code class="parameter">$conn_identifier</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$sql</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$option</code><span class="initializer"> = 0</span></span>): <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span></div>

  <div class="methodsynopsis dc-description"><span class="methodname"><strong>cubrid_execute</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> <code class="parameter">$request_identifier</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$option</code><span class="initializer"> = 0</span></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

    <p class="para rdfs-comment">
      The <span class="function"><strong>cubrid_execute()</strong></span> function is used to execute the
      given SQL statement. It executes the query by using
      <code class="parameter">conn_identifier</code> and SQL, and then returns the
      request identifier created. It is used for simple execution of query,
      where the parameter binding is not needed. In addition, the
      <span class="function"><strong>cubrid_execute()</strong></span> function is used to execute the
      prepared statement by means of <span class="function"><a href="function.cubrid-prepare.php" class="function">cubrid_prepare()</a></span> and
      <span class="function"><a href="function.cubrid-bind.php" class="function">cubrid_bind()</a></span>. At this time, you need to specify
      arguments of <code class="parameter">request_identifier</code> and
      <code class="parameter">option</code>.
    </p>
    <p class="para">
     The <code class="parameter">option</code> is used to determine whether to get OID
     after query execution and whether to execute the query in synchronous or
     asynchronous mode. <strong><code>CUBRID_INCLUDE_OID</code></strong> and <strong><code>CUBRID_ASYNC</code></strong> (or
     <strong><code>CUBRID_EXEC_QUERY_ALL</code></strong> if you want to execute multiple SQL statements) can
     be specified by using a bitwise OR operator. If not specified, neither of
     them isselected. If the flag <strong><code>CUBRID_EXEC_QUERY_ALL</code></strong> is set, a synchronous
     mode (sync_mode) is used to retrieve query results, and in such cases the
     following rules are applied: 
    </p>
    <p class="para">
     <ul class="simplelist">
      <li>The return value is the result of the first query.</li>
      <li>
       If an error occurs in any query, the execution is processed as a
       failure.
      </li>
      <li>
       In a query composed of q1 q2 q3, if an error
       occurs in q2 after q1 succeeds the execution, the result of q1 remains
       valid. That is, the previous successful query executions are not rolled
       back when an error occurs.
      </li>
      <li>
       If a query is executed successfully, the result of the second query can
       be obtained using <span class="function"><a href="function.cubrid-next-result.php" class="function">cubrid_next_result()</a></span>.
      </li>
     </ul>
    </p>
    <p class="para">
     If the first argument is <code class="parameter">request_identifier</code> to
     execute the <span class="function"><a href="function.cubrid-prepare.php" class="function">cubrid_prepare()</a></span> function, you can specify
     an option, <strong><code>CUBRID_ASYNC</code></strong> only.
    </p>
 </div>


  <div class="refsect1 parameters" id="refsect1-function.cubrid-execute-parameters">
 <h3 class="title">Параметри</h3>
 <p class="para">
      <dl>
        
      <dt><code class="parameter">conn_identifier</code></dt>
      <dd><p class="para">Connection identifier.</p></dd>
       
       
      <dt><code class="parameter">sql</code></dt>
      <dd><p class="para">SQL to be executed.</p></dd>
       
       
      <dt><code class="parameter">option</code></dt>
        <dd><p class="para">Query execution option <strong><code>CUBRID_INCLUDE_OID</code></strong>, <strong><code>CUBRID_ASYNC</code></strong>, <strong><code>CUBRID_EXEC_QUERY_ALL</code></strong>.</p></dd>
       
        
      <dt><code class="parameter">request_identifier</code></dt>
      <dd><p class="para"><span class="function"><a href="function.cubrid-prepare.php" class="function">cubrid_prepare()</a></span> identifier.</p></dd>
       
      </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.cubrid-execute-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
    Request identifier, when process is successful and first param is
    conn_identifier; <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>, when process is successful and first argument is
    request_identifier, або <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> в разі помилки.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.cubrid-execute-changelog">
  <h3 class="title">Журнал змін</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Версія</th>
       <th>Опис</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.4.0</td>
       <td>
        Add new option <strong><code>CUBRID_EXEC_QUERY_ALL</code></strong>.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.cubrid-execute-examples">
  <h3 class="title">Приклади</h3>
  <div class="example" id="example-1">
   <p><strong>Приклад #1 <span class="function"><strong>cubrid_execute()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$conn </span><span style="color: #007700">= </span><span style="color: #0000BB">cubrid_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">, </span><span style="color: #0000BB">33000</span><span style="color: #007700">, </span><span style="color: #DD0000">"demodb"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">, </span><span style="color: #DD0000">"SELECT code FROM event WHERE name='100m Butterfly' and gender='M'"</span><span style="color: #007700">, </span><span style="color: #0000BB">CUBRID_ASYNC</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">cubrid_fetch_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">, </span><span style="color: #0000BB">CUBRID_ASSOC</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$event_code </span><span style="color: #007700">= </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">"code"</span><span style="color: #007700">];<br /><br /></span><span style="color: #0000BB">cubrid_close_request</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$history_req </span><span style="color: #007700">= </span><span style="color: #0000BB">cubrid_prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">, </span><span style="color: #DD0000">"SELECT * FROM history WHERE event_code=?"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">cubrid_bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$history_req</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">$event_code</span><span style="color: #007700">, </span><span style="color: #DD0000">"number"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$history_req</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%-20s %-9s %-10s %-5s\n"</span><span style="color: #007700">, </span><span style="color: #DD0000">"athlete"</span><span style="color: #007700">, </span><span style="color: #DD0000">"host_year"</span><span style="color: #007700">, </span><span style="color: #DD0000">"score"</span><span style="color: #007700">, </span><span style="color: #DD0000">"unit"</span><span style="color: #007700">);<br />while (</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">cubrid_fetch_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$history_req</span><span style="color: #007700">, </span><span style="color: #0000BB">CUBRID_ASSOC</span><span style="color: #007700">)) {<br />    </span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%-20s %-9s %-10s %-5s\n"</span><span style="color: #007700">, <br />        </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">"athlete"</span><span style="color: #007700">], </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">"host_year"</span><span style="color: #007700">], </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">"score"</span><span style="color: #007700">], </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">"unit"</span><span style="color: #007700">]);<br />}<br /><br /></span><span style="color: #0000BB">cubrid_close_request</span><span style="color: #007700">(</span><span style="color: #0000BB">$history_req</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">cubrid_disconnect</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

    <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">athlete              host_year score      unit 
Phelps Michael       2004      51.25      time</pre>
</div>
   </div>
  </div>
 </div>


   <div class="refsect1 seealso" id="refsect1-function.cubrid-execute-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
   <li><span class="function"><a href="function.cubrid-prepare.php" class="function" rel="rdfs-seeAlso">cubrid_prepare()</a> - Prepare a SQL statement for execution</span></li>
   <li><span class="function"><a href="function.cubrid-bind.php" class="function" rel="rdfs-seeAlso">cubrid_bind()</a> - Bind variables to a prepared statement as parameters</span></li>
   <li><span class="function"><a href="function.cubrid-next-result.php" class="function" rel="rdfs-seeAlso">cubrid_next_result()</a> - Get result of next query when executing multiple SQL statements</span></li>
   <li><span class="function"><a href="function.cubrid-close-request.php" class="function" rel="rdfs-seeAlso">cubrid_close_request()</a> - Close the request handle</span></li>
   <li><span class="function"><a href="function.cubrid-commit.php" class="function" rel="rdfs-seeAlso">cubrid_commit()</a> - Commit a transaction</span></li>
   <li><span class="function"><a href="function.cubrid-rollback.php" class="function" rel="rdfs-seeAlso">cubrid_rollback()</a> - Roll back a transaction</span></li>
   </ul>
  </p>
  </div>


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