<?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 => 'ru',
  ),
  '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' => 'ru',
    '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.reset.php" class="methodname">SQLite3Stmt::reset()</a></span> должен вызываться до первого вызова
    <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"><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">:</code>).
       Положительные параметры начинаются с 1.
      </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>.
       Раньше, если тип опущен, то по умолчанию использовался <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>, он всегда обрабатывается как
        <strong><code><a href="sqlite3.constants.php#constant.sqlite3-null">SQLITE3_NULL</a></code></strong>, независимо от заданного <code class="parameter">type</code>.
       </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); ?>