Sophie

Sophie

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

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>Bind variables to a prepared statement as parameters</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="ref.cubrid.html">CUBRID Functions</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.cubrid-close-prepare.html">cubrid_close_prepare</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-bind" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">cubrid_bind</h1>
  <p class="verinfo">(PECL CUBRID &gt;= 8.3.0)</p><p class="refpurpose"><span class="refname">cubrid_bind</span> &mdash; <span class="dc-title">Bind variables to a prepared statement as parameters</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.cubrid-bind-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>cubrid_bind</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$req_identifier</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$bind_index</code></span>
   , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$bind_value</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$bind_value_type</code></span>
  ] )</div>

  <p class="para rdfs-comment">
   The  <span class="function"><strong>cubrid_bind()</strong></span> function is used to bind values to a
   corresponding named or question mark placeholder in the SQL statement that
   was passed to  <span class="function"><a href="function.cubrid-prepare.html" class="function">cubrid_prepare()</a></span>. If
   <em><code class="parameter">bind_value_type</code></em> is not given, string will be the
   default.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    If the type of data to be bound is BLOB/CLOB, CUBRID will try to map the
    data as a PHP stream. If the actually bind value type is not stream,
    CUBRID will convert it to string, and use it as the full path and file
    name of a file on the client filesystem.
   </p>
   <p class="para">
    If the type of data to be bound explicitly is ENUM, the $bind_value
    argument should be the enum element which is in string format.
   </p>
   <p class="para">
    In CUBRID shard envrioment, the $bind_value_type must be included in 
    the cubrid_bind function.
   </p>
  </p></blockquote>
  <p class="para">
  The following table shows the types of substitute values.
  </p>
  <p class="para">
   <table class="doctable table">
    <caption><strong>CUBRID Bind Date Types</strong></caption>
    
     <thead>
      <tr>
       <th>Support</th>
       <th>Bind Type</th>
       <th>Corresponding SQL Type</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>Supported</td>
       <td>STRING</td>
       <td>CHAR, VARCHAR</td>
      </tr>

      <tr>
       <td class="empty">&nbsp;</td>
       <td>NCHAR</td>
       <td>NCHAR, NVARCHAR</td>
      </tr>

      <tr>
       <td class="empty">&nbsp;</td>
       <td>BIT</td>
       <td>BIT, VARBIT</td>
      </tr>

      <tr>
       <td class="empty">&nbsp;</td>
       <td>NUMERIC or NUMBER</td>
       <td>SHORT, INT, NUMERIC</td>
      </tr>

      <tr>
       <td class="empty">&nbsp;</td>
       <td>FLOAT</td>
       <td>FLOAT</td>
      </tr>

      <tr>
       <td class="empty">&nbsp;</td>
       <td>DOUBLE</td>
       <td>DOUBLE</td>
      </tr>

      <tr>
       <td class="empty">&nbsp;</td>
       <td>TIME</td>
       <td>TIME</td>
      </tr>

      <tr>
       <td class="empty">&nbsp;</td>
       <td>DATE</td>
       <td>DATE</td>
      </tr>

      <tr>
       <td class="empty">&nbsp;</td>
       <td>TIMESTAMP</td>
       <td>TIMESTAMP</td>
      </tr>

      <tr>
       <td class="empty">&nbsp;</td>
       <td>OBJECT</td>
       <td>OBJECT</td>
      </tr>

      <tr>
       <td class="empty">&nbsp;</td>
       <td>ENUM</td>
       <td>ENUM</td>
      </tr>

      <tr>
       <td class="empty">&nbsp;</td>
       <td>BLOB</td>
       <td>BLOB</td>
      </tr>

      <tr>
       <td class="empty">&nbsp;</td>
       <td>CLOB</td>
       <td>CLOB</td>
      </tr>

      <tr>
       <td class="empty">&nbsp;</td>
       <td>NULL</td>
       <td>NULL</td>
      </tr>

      <tr>
       <td>Not supported</td>
       <td>SET</td>
       <td>SET</td>
      </tr>

      <tr>
       <td class="empty">&nbsp;</td>
       <td>MULTISET</td>
       <td>MULTISET</td>
      </tr>

      <tr>
       <td class="empty">&nbsp;</td>
       <td>SEQUENCE</td>
       <td>SEQUENCE</td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


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

    <dt>

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

   </dt>

   <dt>

  <span class="term"><em><code class="parameter">bind_index</code></em></span>
  <dd>
<p class="para">Location of binding parameters. It starts with 1.</p></dd>

   </dt>

   <dt>

  <span class="term"><em><code class="parameter">bind_value</code></em></span>
  <dd>
<p class="para">Actual value for binding.</p></dd>

   </dt>

   <dt>

  <span class="term"><em><code class="parameter">bind_value_type</code></em></span>
  <dd>
<p class="para">A type of the value to bind. (It is omitted by default.
    Thus, the system internally uses string by default. However, you need to
    specify the exact type of the value as an argument when they are NCHAR,
    BIT, or BLOB/CLOB).</p></dd>

   </dt>

  </dl>

  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.cubrid-bind-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
    <strong><code>TRUE</code></strong>, when process is successful.
  </p>
  <p class="para">
    <strong><code>FALSE</code></strong>, when process is unsuccessful.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.cubrid-bind-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.3.1</td>
       <td>
        Added BLOB/CLOB data types support.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.cubrid-bind-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-998">
   <p><strong>Example #1  <span class="function"><strong>cubrid_bind()</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">,&nbsp;</span><span style="color: #DD0000">"dba"</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;sports='Basketball'&nbsp;and&nbsp;gender='M'"</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">$game_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;athlete_code&nbsp;FROM&nbsp;game&nbsp;WHERE&nbsp;host_year=1992&nbsp;and&nbsp;event_code=?&nbsp;and&nbsp;nation_code='USA'"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">cubrid_bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$game_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">$game_req</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"---&nbsp;Dream&nbsp;Team&nbsp;(1992&nbsp;United&nbsp;States&nbsp;men's&nbsp;Olympic&nbsp;basketball&nbsp;team)&nbsp;---\n"</span><span style="color: #007700">);<br />while&nbsp;(</span><span style="color: #0000BB">$athlete_code&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">$game_req</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CUBRID_NUM</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$athlete_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;name&nbsp;FROM&nbsp;athlete&nbsp;WHERE&nbsp;code=?&nbsp;AND&nbsp;nation_code='USA'&nbsp;AND&nbsp;event='Basketball'&nbsp;AND&nbsp;gender='M'"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$athlete_req</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$athlete_code</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">],&nbsp;</span><span style="color: #DD0000">"number"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$athlete_req</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_fetch_assoc</span><span style="color: #007700">(</span><span style="color: #0000BB">$athlete_req</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">"name"</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">$game_req</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">cubrid_close_request</span><span style="color: #007700">(</span><span style="color: #0000BB">$athlete_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>
--- Dream Team (1992 United States men&#039;s Olympic basketball team) ---
Stockton John
Robinson David
Pippen Scottie
Mullin C.
Malone Karl
Laettner C.
Jordan Michael
Johnson Earvin
Ewing Patrick
Drexler Clyde
Bird Larry
Barkley Charles
</pre></div>
   </div>
  </div>

  <div class="example" id="example-999">
   <p><strong>Example #2  <span class="function"><strong>cubrid_bind()</strong></span> BLOB/CLOB example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$con&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">,&nbsp;</span><span style="color: #DD0000">"dba"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">$con</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$con</span><span style="color: #007700">,</span><span style="color: #DD0000">"DROP&nbsp;TABLE&nbsp;if&nbsp;exists&nbsp;php_cubrid_lob_test"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$con</span><span style="color: #007700">,</span><span style="color: #DD0000">"CREATE&nbsp;TABLE&nbsp;php_cubrid_lob_test&nbsp;(doc_content&nbsp;CLOB)"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$sql&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"INSERT&nbsp;INTO&nbsp;php_cubrid_lob_test(doc_content)&nbsp;VALUES(?)"</span><span style="color: #007700">;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$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">$con</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sql</span><span style="color: #007700">);&nbsp;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"book.txt"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"rb"</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"clob"</span><span style="color: #007700">);&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">);&nbsp;&nbsp;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>

  <div class="example" id="example-1000">
   <p><strong>Example #3  <span class="function"><strong>cubrid_bind()</strong></span> BLOB/CLOB example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$con&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">,&nbsp;</span><span style="color: #DD0000">"dba"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">$con</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$con</span><span style="color: #007700">,</span><span style="color: #DD0000">"DROP&nbsp;TABLE&nbsp;if&nbsp;exists&nbsp;php_cubrid_lob_test"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$con</span><span style="color: #007700">,</span><span style="color: #DD0000">"CREATE&nbsp;TABLE&nbsp;php_cubrid_lob_test&nbsp;(image&nbsp;BLOB)"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$sql&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"INSERT&nbsp;INTO&nbsp;php_cubrid_lob_test(image)&nbsp;VALUES(?)"</span><span style="color: #007700">;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$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">$con</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sql</span><span style="color: #007700">);&nbsp;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"cubrid_logo.png"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"blob"</span><span style="color: #007700">);&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">);&nbsp;&nbsp;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.cubrid-bind-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="function"><a href="function.cubrid-execute.html" class="function" rel="rdfs-seeAlso">cubrid_execute()</a> - Execute a prepared SQL statement</span></li>
    <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>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="ref.cubrid.html">CUBRID Functions</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.cubrid-close-prepare.html">cubrid_close_prepare</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>