<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.sqlite3stmt.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'ja',
  ),
  'this' => 
  array (
    0 => 'sqlite3stmt.bindparam.php',
    1 => 'SQLite3Stmt::bindParam',
    2 => 'パラメータを変数にバインドする',
  ),
  'up' => 
  array (
    0 => 'class.sqlite3stmt.php',
    1 => 'SQLite3Stmt',
  ),
  'prev' => 
  array (
    0 => 'class.sqlite3stmt.php',
    1 => 'SQLite3Stmt',
  ),
  'next' => 
  array (
    0 => 'sqlite3stmt.bindvalue.php',
    1 => 'SQLite3Stmt::bindValue',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ja',
    'path' => 'reference/sqlite3/sqlite3stmt/bindparam.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="sqlite3stmt.bindparam" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SQLite3Stmt::bindParam</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">SQLite3Stmt::bindParam</span> &mdash; <span class="dc-title">パラメータを変数にバインドする</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-sqlite3stmt.bindparam-description">
  <h3 class="title">説明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>SQLite3Stmt::bindParam</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.integer.php" class="type int">int</a></span></span> <code class="parameter">$param</code></span>, <span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter reference">&$var</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$type</code><span class="initializer"> = <strong><code><a href="sqlite3.constants.php#constant.sqlite3-text">SQLITE3_TEXT</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">
   パラメータを変数にバインドします。
  </p>
  <div class="caution"><strong class="caution">警告</strong>
   <p class="para">
    PHP 7.2.14 と 7.3.0 より前のバージョンでは、
    バインドされた値が適切に後の <span class="methodname"><a href="sqlite3stmt.execute.php" class="methodname">SQLite3Stmt::execute()</a></span> 
    の呼び出しで更新されるべき場合、
    <span class="methodname"><a href="sqlite3stmt.execute.php" class="methodname">SQLite3Stmt::execute()</a></span> をはじめて呼んだ後に
    <span class="methodname"><a href="sqlite3stmt.reset.php" class="methodname">SQLite3Stmt::reset()</a></span> を呼び出さなければなりませんでした。
    <span class="methodname"><a href="sqlite3stmt.reset.php" class="methodname">SQLite3Stmt::reset()</a></span> が呼び出されなかった場合、
    <span class="methodname"><strong>SQLite3Stmt::bindParam()</strong></span> に渡された変数に代入された値が変化したり、
    <span class="methodname"><strong>SQLite3Stmt::bindParam()</strong></span> を再度呼び出したりしても、
    バインドされた値は決して変わりませんでした。
   </p>
  </div>
 </div>


 <div class="refsect1 parameters" id="refsect1-sqlite3stmt.bindparam-parameters">
  <h3 class="title">パラメータ</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">param</code></dt>
     <dd>
      <p class="para">
       バインドされるべき文中の値を識別する
       <span class="type"><a href="language.types.string.php" class="type string">string</a></span> (名前付きパラメータの場合) または
       (位置パラメータの場合) <span class="type"><a href="language.types.integer.php" class="type int">int</a></span>。
       名前付きパラメータがコロン (<code class="literal">:</code>) や
       アットマーク (<code class="literal">@</code>) 
       ではじまっていない場合、コロンが自動的に名前の前に付加されます。
       位置パラメータは <code class="literal">1</code> から始まります。
      </p>
     </dd>
    
    
     <dt><code class="parameter">var</code></dt>
     <dd>
      <p class="para">
       変数にバインドするパラメータ。
      </p>
     </dd>
    
    
     <dt><code class="parameter">type</code></dt>
     <dd>
      <p class="para">
       バインドするパラメータのデータ型。
       <ul class="itemizedlist">
        <li class="listitem">
         <p class="para">
          <strong><code><a href="sqlite3.constants.php#constant.sqlite3-integer">SQLITE3_INTEGER</a></code></strong>: 符号付き整数。
          値の大きさに応じて 1, 2, 3, 4, 6, あるいは 8 バイトで格納されます。
         </p>
        </li>
        <li class="listitem">
         <p class="para">
          <strong><code><a href="sqlite3.constants.php#constant.sqlite3-float">SQLITE3_FLOAT</a></code></strong>: 浮動小数点数値。
          8 バイトの IEEE 浮動小数点数値として格納されます。
         </p>
        </li>
        <li class="listitem">
         <p class="para">
          <strong><code><a href="sqlite3.constants.php#constant.sqlite3-text">SQLITE3_TEXT</a></code></strong>: テキスト文字列。
          データベースのエンコーディング (UTF-8, UTF-16BE あるいは UTF-16-LE)
          を用いて格納されます。
         </p>
        </li>
        <li class="listitem">
         <p class="para">
          <strong><code><a href="sqlite3.constants.php#constant.sqlite3-blob">SQLITE3_BLOB</a></code></strong>: blob データ。
          入力がそのままの形式で格納されます。
         </p>
        </li>
        <li class="listitem">
         <p class="para">
          <strong><code><a href="sqlite3.constants.php#constant.sqlite3-null">SQLITE3_NULL</a></code></strong>: NULL 値。
         </p>
        </li>
       </ul>
      </p>
      <p class="para">
       PHP 7.0.7 以降では、
       <code class="parameter">type</code> が省略されると、
       自動的に <code class="parameter">var</code> の型から検出します:
       <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span>
       と <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> 型は <strong><code><a href="sqlite3.constants.php#constant.sqlite3-integer">SQLITE3_INTEGER</a></code></strong> として扱われ、
       <span class="type"><a href="language.types.float.php" class="type float">float</a></span> は <strong><code><a href="sqlite3.constants.php#constant.sqlite3-float">SQLITE3_FLOAT</a></code></strong>、
       <span class="type"><a href="language.types.null.php" class="type null">null</a></span> は <strong><code><a href="sqlite3.constants.php#constant.sqlite3-null">SQLITE3_NULL</a></code></strong>、
       そして、これら以外は全て <strong><code><a href="sqlite3.constants.php#constant.sqlite3-text">SQLITE3_TEXT</a></code></strong> として扱われます。
       これより前のバージョンでは、<code class="parameter">type</code> が省略されると、
       デフォルトの型 <strong><code><a href="sqlite3.constants.php#constant.sqlite3-text">SQLITE3_TEXT</a></code></strong> になっていました。
      </p>
      <blockquote class="note"><p><strong class="note">注意</strong>: 
       <p class="para">
        <code class="parameter">var</code> が <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> の場合、
        与えられた <code class="parameter">type</code> に関わらず、
        常に <strong><code><a href="sqlite3.constants.php#constant.sqlite3-null">SQLITE3_NULL</a></code></strong> として扱われます。
       </p>
      </p></blockquote>
     </dd>
    
   </dl>
  </p>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-sqlite3stmt.bindparam-returnvalues">
  <h3 class="title">戻り値</h3>
  <p class="para">
   パラメータを変数にバインドした場合に <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>、
   失敗した場合に <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> を返します。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-sqlite3stmt.bindparam-changelog">
  <h3 class="title">変更履歴</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>バージョン</th>
      <th>説明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>7.4.0</td>
      <td>
       <code class="parameter">param</code> は、
       <code class="literal">@param</code> 記法もサポートするようになりました。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-sqlite3stmt.bindparam-examples">
  <h3 class="title">例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>例1 <span class="function"><strong>SQLite3Stmt::bindParam()</strong></span> の使い方</strong></p>
    <div class="example-contents"><p>
     この例は、バインドするパラメータがひとつだけのプリペアドステートメントを使い、
     どのようにして異なる値を持つ複数の行を挿入するかを示しています。
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$db </span><span style="color: #007700">= new </span><span style="color: #0000BB">SQLite3</span><span style="color: #007700">(</span><span style="color: #DD0000">':memory:'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">"CREATE TABLE foo (bar TEXT)"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$stmt </span><span style="color: #007700">= </span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">prepare</span><span style="color: #007700">(</span><span style="color: #DD0000">"INSERT INTO foo VALUES (:bar)"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">bindParam</span><span style="color: #007700">(</span><span style="color: #DD0000">':bar'</span><span style="color: #007700">, </span><span style="color: #0000BB">$bar</span><span style="color: #007700">, </span><span style="color: #0000BB">SQLITE3_TEXT</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$bar </span><span style="color: #007700">= </span><span style="color: #DD0000">'baz'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$bar </span><span style="color: #007700">= </span><span style="color: #0000BB">42</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$res </span><span style="color: #007700">= </span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT * FROM foo"</span><span style="color: #007700">);<br />while ((</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">$res</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetchArray</span><span style="color: #007700">(</span><span style="color: #0000BB">SQLITE3_ASSOC</span><span style="color: #007700">))) {<br />    </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$row</span><span style="color: #007700">);<br />}<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">array(1) {
  [&quot;bar&quot;]=&gt;
  string(3) &quot;baz&quot;
}
array(1) {
  [&quot;bar&quot;]=&gt;
  string(2) &quot;42&quot;
}</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-sqlite3stmt.bindparam-seealso">
  <h3 class="title">参考</h3>
  <ul class="simplelist">
   <li><span class="methodname"><a href="sqlite3stmt.bindvalue.php" class="methodname" rel="rdfs-seeAlso">SQLite3Stmt::bindValue()</a> - パラメータの値を変数にバインドする</span></li>
   <li><span class="methodname"><a href="sqlite3.prepare.php" class="methodname" rel="rdfs-seeAlso">SQLite3::prepare()</a> - 実行する SQL 文を準備する</span></li>
  </ul>
 </div>


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