<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.pdostatement.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'pdostatement.bindcolumn.php',
    1 => 'PDOStatement::bindColumn',
    2 => 'Bind a column to a PHP variable',
  ),
  'up' => 
  array (
    0 => 'class.pdostatement.php',
    1 => 'PDOStatement',
  ),
  'prev' => 
  array (
    0 => 'class.pdostatement.php',
    1 => 'PDOStatement',
  ),
  'next' => 
  array (
    0 => 'pdostatement.bindparam.php',
    1 => 'PDOStatement::bindParam',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/pdo/pdostatement/bindcolumn.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="pdostatement.bindcolumn" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">PDOStatement::bindColumn</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7, PHP 8, PECL pdo &gt;= 0.1.0)</p><p class="refpurpose"><span class="refname">PDOStatement::bindColumn</span> &mdash; <span class="dc-title">
   Bind a column to a PHP variable
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-pdostatement.bindcolumn-description">
  <h3 class="title">Опис</h3>
   <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>PDOStatement::bindColumn</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<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">$column</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<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>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<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"> = PDO::PARAM_STR</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$maxLength</code><span class="initializer"> = 0</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$driverOptions</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span><br>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>


  <p class="para rdfs-comment">
   <span class="methodname"><strong>PDOStatement::bindColumn()</strong></span> arranges to have a
   particular variable bound to a given column in the result-set from a
   query.  Each call to <span class="methodname"><a href="pdostatement.fetch.php" class="methodname">PDOStatement::fetch()</a></span> or
   <span class="methodname"><a href="pdostatement.fetchall.php" class="methodname">PDOStatement::fetchAll()</a></span> will update all the variables
   that are bound to columns.
  </p>
  <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
   <p class="para">
    Since information about the columns is not always available to PDO until
    the statement is executed, portable applications should call this
    function <em>after</em> <span class="methodname"><a href="pdostatement.execute.php" class="methodname">PDOStatement::execute()</a></span>.
   </p>
   <p class="para">
    However, to be able to bind a LOB column as a stream when using the
    <em>PgSQL driver</em>, applications should call this method
    <em>before</em> calling <span class="methodname"><a href="pdostatement.execute.php" class="methodname">PDOStatement::execute()</a></span>,
    otherwise the large object OID will be returned as an integer.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-pdostatement.bindcolumn-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">column</code></dt>
     <dd>
      <p class="para">
       Number of the column (1-indexed) or name of the column in the result set.
       If using the column name, be aware that the name should match the
       case of the column, as returned by the driver.
      </p>
     </dd>
    
    
     <dt><code class="parameter">var</code></dt>
     <dd>
      <p class="para">
       Name of the PHP variable to which the column will be bound.
      </p>
     </dd>
    
    
     <dt><code class="parameter">type</code></dt>
     <dd>
      <p class="para">
       Data type of the parameter, specified by the <a href="pdo.constants.php" class="link"><code class="literal">PDO::PARAM_*</code>
       constants</a>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">maxLength</code></dt>
     <dd>
      <p class="para">
       A hint for pre-allocation.
      </p>
     </dd>
    
    
     <dt><code class="parameter">driverOptions</code></dt>
     <dd>
      <p class="para">
       Optional parameter(s) for the driver.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-pdostatement.bindcolumn-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 errors" id="refsect1-pdostatement.bindcolumn-errors">
  <h3 class="title">Помилки/виключення</h3>
  <p class="para">
Видає помилку рівня <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong>, якщо атрибут
<strong><code><a href="pdo.constants.php#pdo.constants.attr-errmode">PDO::ATTR_ERRMODE</a></code></strong> дорівнює
<strong><code><a href="pdo.constants.php#pdo.constants.errmode-warning">PDO::ERRMODE_WARNING</a></code></strong>.
</p>
<p class="para">
Викидає <span class="classname"><a href="class.pdoexception.php" class="classname">PDOException</a></span>, якщо атрибут
<strong><code><a href="pdo.constants.php#pdo.constants.attr-errmode">PDO::ATTR_ERRMODE</a></code></strong> дорівнює
<strong><code><a href="pdo.constants.php#pdo.constants.errmode-exception">PDO::ERRMODE_EXCEPTION</a></code></strong>.
</p>
 </div>


 <div class="refsect1 examples" id="refsect1-pdostatement.bindcolumn-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 Binding result set output to PHP variables</strong></p>
    <div class="example-contents"><p>
     Binding columns in the result set to PHP variables is an effective
     way to make the data contained in each row immediately available to
     your application. The following example demonstrates how PDO allows
     you to bind and retrieve columns with a variety of options and with
     intelligent defaults.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$stmt </span><span style="color: #007700">= </span><span style="color: #0000BB">$dbh</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">prepare</span><span style="color: #007700">(</span><span style="color: #DD0000">'SELECT name, colour, calories FROM fruit'</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: #FF8000">/* Bind by column number */<br /></span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">bindColumn</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">$name</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">bindColumn</span><span style="color: #007700">(</span><span style="color: #0000BB">2</span><span style="color: #007700">, </span><span style="color: #0000BB">$colour</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Bind by column name */<br /></span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">bindColumn</span><span style="color: #007700">(</span><span style="color: #DD0000">'calories'</span><span style="color: #007700">, </span><span style="color: #0000BB">$cals</span><span style="color: #007700">);<br /><br />while (</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch</span><span style="color: #007700">(</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">FETCH_BOUND</span><span style="color: #007700">)) {<br />    print </span><span style="color: #0000BB">$name </span><span style="color: #007700">. </span><span style="color: #DD0000">"\t" </span><span style="color: #007700">. </span><span style="color: #0000BB">$colour </span><span style="color: #007700">. </span><span style="color: #DD0000">"\t" </span><span style="color: #007700">. </span><span style="color: #0000BB">$cals </span><span style="color: #007700">. </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}</span></span></code></div>
    </div>

    <div class="example-contents"><p>Поданий вище приклад виведе щось
схоже на:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">apple   red     150
banana  yellow  175
kiwi    green   75
orange  orange  150
mango   red     200
strawberry      red     25</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-pdostatement.bindcolumn-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="pdostatement.execute.php" class="methodname" rel="rdfs-seeAlso">PDOStatement::execute()</a> - Executes a prepared statement</span></li>
    <li><span class="methodname"><a href="pdostatement.fetch.php" class="methodname" rel="rdfs-seeAlso">PDOStatement::fetch()</a> - Fetches the next row from a result set</span></li>
    <li><span class="methodname"><a href="pdostatement.fetchall.php" class="methodname" rel="rdfs-seeAlso">PDOStatement::fetchAll()</a> - Fetches the remaining rows from a result set</span></li>
    <li><span class="methodname"><a href="pdostatement.fetchcolumn.php" class="methodname" rel="rdfs-seeAlso">PDOStatement::fetchColumn()</a> - Returns a single column from the next row of a result set</span></li>
   </ul>
  </p>
 </div>


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