Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 2363

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!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>Execute a prepared SQL statement</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.cubrid-error-msg.html">cubrid_error_msg</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.cubrid-fetch.html">cubrid_fetch</a></div>
 <div class="up"><a href="ref.cubrid.html">CUBRID Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><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">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">resource</span> <span class="methodname"><strong>cubrid_execute</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$conn_identifier</code></span>  
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$sql</code></span>  
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$option</code></span>  
  ] )</div>

  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>cubrid_execute</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$request_identifier</code></span>  
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$option</code></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
      <em><code class="parameter">conn_identifier</code></em> 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.html" class="function">cubrid_prepare()</a></span> and
       <span class="function"><a href="function.cubrid-bind.html" class="function">cubrid_bind()</a></span>. At this time, you need to specify
      arguments of <em><code class="parameter">request_identifier</code></em> and
      <em><code class="parameter">option</code></em>.
    </p>
    <p class="para">
     The <em><code class="parameter">option</code></em> is used to determine whether to get OID
     after query execution and whether to execute the query in synchronous or
     asynchronous mode. CUBRID_INCLUDE_OID and CUBRID_ASYNC (or
     CUBRID_EXEC_QUERY_ALL 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 CUBRID_EXEC_QUERY_ALL 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 class="member">The return value is the result of the first query.</li>
      <li class="member">
       If an error occurs in any query, the execution is processed as a
       failure.
      </li>
      <li class="member">
       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 class="member">
       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.html" class="function">cubrid_next_result()</a></span>.
      </li>
     </ul>
    </p>
    <p class="para">
     If the first argument is <em><code class="parameter">request_identifier</code></em> to
     execute the  <span class="function"><a href="function.cubrid-prepare.html" class="function">cubrid_prepare()</a></span> function, you can specify
     an option, CUBRID_ASYNC only.
    </p>
 </div>


  <div class="refsect1 parameters" id="refsect1-function.cubrid-execute-parameters">
 <h3 class="title">Parameters</h3>
 <p class="para">
      <dl>

        <dt>

      <span class="term"><em><code class="parameter">conn_identifier</code></em></span>
      <dd>
<p class="para">Connection identifier.</p></dd>

       </dt>

       <dt>

      <span class="term"><em><code class="parameter">sql</code></em></span>
      <dd>
<p class="para">SQL to be executed.</p></dd>

       </dt>

       <dt>

      <span class="term"><em><code class="parameter">option</code></em></span>
      <dd>
<p class="para">Query execution option CUBRID_INCLUDE_OID, CUBRID_ASYNC, CUBRID_EXEC_QUERY_ALL.</p></dd>

       </dt>

        <dt>

      <span class="term"><em><code class="parameter">request_identifier</code></em></span>
      <dd>
<p class="para"> <span class="function"><a href="function.cubrid-prepare.html" class="function">cubrid_prepare()</a></span> identifier.</p></dd>

       </dt>

      </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.cubrid-execute-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
    Request identifier, when process is successful and first param is
    conn_identifier; <strong><code>TRUE</code></strong>, when process is successful and first argument is
    request_identifier.
  </p>
  <p class="para">
    <strong><code>FALSE</code></strong>, when process is unsuccessful.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.cubrid-execute-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

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

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.cubrid-execute-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-1017">
   <p><strong>Example #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&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">33000</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"demodb"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;code&nbsp;FROM&nbsp;event&nbsp;WHERE&nbsp;name='100m&nbsp;Butterfly'&nbsp;and&nbsp;gender='M'"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CUBRID_ASYNC</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_fetch_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CUBRID_ASSOC</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$event_code&nbsp;</span><span style="color: #007700">=&nbsp;</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&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;*&nbsp;FROM&nbsp;history&nbsp;WHERE&nbsp;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">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$event_code</span><span style="color: #007700">,&nbsp;</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&nbsp;%-9s&nbsp;%-10s&nbsp;%-5s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"athlete"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"host_year"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"score"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"unit"</span><span style="color: #007700">);<br />while&nbsp;(</span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</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">,&nbsp;</span><span style="color: #0000BB">CUBRID_ASSOC</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%-20s&nbsp;%-9s&nbsp;%-10s&nbsp;%-5s\n"</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">"athlete"</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">"host_year"</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">"score"</span><span style="color: #007700">],&nbsp;</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>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
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">See Also</h3>
  <p class="para">
   <ul class="simplelist">
   <li class="member"> <span class="function"><a href="function.cubrid-prepare.html" class="function" rel="rdfs-seeAlso">cubrid_prepare()</a> - Prepare a SQL statement for execution</span></li>
   <li class="member"> <span class="function"><a href="function.cubrid-bind.html" class="function" rel="rdfs-seeAlso">cubrid_bind()</a> - Bind variables to a prepared statement as parameters</span></li>
   <li class="member"> <span class="function"><a href="function.cubrid-next-result.html" class="function" rel="rdfs-seeAlso">cubrid_next_result()</a> - Get result of next query when executing multiple SQL statements</span></li>
   <li class="member"> <span class="function"><a href="function.cubrid-close-request.html" class="function" rel="rdfs-seeAlso">cubrid_close_request()</a> - Close the request handle</span></li>
   <li class="member"> <span class="function"><a href="function.cubrid-commit.html" class="function" rel="rdfs-seeAlso">cubrid_commit()</a> - Commit a transaction</span></li>
   <li class="member"> <span class="function"><a href="function.cubrid-rollback.html" class="function" rel="rdfs-seeAlso">cubrid_rollback()</a> - Roll back a 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.cubrid-error-msg.html">cubrid_error_msg</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.cubrid-fetch.html">cubrid_fetch</a></div>
 <div class="up"><a href="ref.cubrid.html">CUBRID Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>