Source of: /manual/en/pdostatement.bindvalue.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = 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 => 'en',
),
'this' =>
array (
0 => 'pdostatement.bindvalue.php',
1 => 'PDOStatement->bindValue',
),
'up' =>
array (
0 => 'class.pdostatement.php',
1 => 'The PDOStatement class',
),
'prev' =>
array (
0 => 'pdostatement.bindparam.php',
1 => 'PDOStatement->bindParam',
),
'next' =>
array (
0 => 'pdostatement.closecursor.php',
1 => 'PDOStatement->closeCursor',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<div id="pdostatement.bindvalue" class="refentry">
<div class="refnamediv">
<h1 class="refname">PDOStatement->bindValue</h1>
<p class="verinfo">(PHP 5 >= 5.1.0, PECL pdo >= 1.0.0)</p><p class="refpurpose"><span class="refname">PDOStatement->bindValue</span> — <span class="dc-title">
Binds a value to a parameter
</span></p>
</div>
<a name="pdostatement.bindvalue.description"></a><div class="refsect1 description">
<h3 class="title">Description</h3>
<div class="methodsynopsis dc-description">
<span class="type">bool</span> <span class="methodname"><b>PDOStatement::bindValue</b></span>
( <span class="methodparam"><span class="type"><a href="language.pseudo-types.php#language.types.mixed" class="type mixed">mixed</a></span> <tt class="parameter">$parameter</tt></span>
, <span class="methodparam"><span class="type"><a href="language.pseudo-types.php#language.types.mixed" class="type mixed">mixed</a></span> <tt class="parameter">$value</tt></span>
[, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$data_type</tt></span>
] )</div>
<p class="para rdfs-comment">
Binds a value to a corresponding named or question mark placeholder
in the SQL statement that was use to prepare the statement.
</p>
</div>
<a name="pdostatement.bindvalue.parameters"></a><div class="refsect1 parameters">
<h3 class="title">Parameters</h3>
<p class="para">
</p><dl>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">parameter</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
Parameter identifier. For a prepared statement using named
placeholders, this will be a parameter name of the form
<var class="varname">:name</var>. For a prepared statement using
question mark placeholders, this will be the 1-indexed position of
the parameter.
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">value</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
The value to bind to the parameter.
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">data_type</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
Explicit data type for the parameter using the PDO::PARAM_*
constants.
Defaults to <b><tt class="constant">PDO::PARAM_STR</tt></b>.
</p>
</dd>
</dl>
<p>
</p>
</div>
<a name="pdostatement.bindvalue.returnvalues"></a><div class="refsect1 returnvalues">
<h3 class="title">Return Values</h3>
<p class="para">
Returns <b><tt class="constant">TRUE</tt></b> on success or <b><tt class="constant">FALSE</tt></b> on failure.
</p>
</div>
<a name="pdostatement.bindvalue.examples"></a><div class="refsect1 examples">
<h3 class="title">Examples</h3>
<div class="example"><p><b>Example #1 Execute a prepared statement with named placeholders</b></p>
<div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">/* Execute a prepared statement by binding PHP variables */<br /></span><span style="color: #0000BB">$calories </span><span style="color: #007700">= </span><span style="color: #0000BB">150</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$colour </span><span style="color: #007700">= </span><span style="color: #DD0000">'red'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$sth </span><span style="color: #007700">= </span><span style="color: #0000BB">$dbh</span><span style="color: #007700">-></span><span style="color: #0000BB">prepare</span><span style="color: #007700">(</span><span style="color: #DD0000">'SELECT name, colour, calories<br /> FROM fruit<br /> WHERE calories < :calories AND colour = :colour'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$sth</span><span style="color: #007700">-></span><span style="color: #0000BB">bindValue</span><span style="color: #007700">(</span><span style="color: #DD0000">':calories'</span><span style="color: #007700">, </span><span style="color: #0000BB">$calories</span><span style="color: #007700">, </span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">PARAM_INT</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$sth</span><span style="color: #007700">-></span><span style="color: #0000BB">bindValue</span><span style="color: #007700">(</span><span style="color: #DD0000">':colour'</span><span style="color: #007700">, </span><span style="color: #0000BB">$colour</span><span style="color: #007700">, </span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">PARAM_STR</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$sth</span><span style="color: #007700">-></span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
</div>
<div class="example"><p><b>Example #2 Execute a prepared statement with question mark placeholders</b></p>
<div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">/* Execute a prepared statement by binding PHP variables */<br /></span><span style="color: #0000BB">$calories </span><span style="color: #007700">= </span><span style="color: #0000BB">150</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$colour </span><span style="color: #007700">= </span><span style="color: #DD0000">'red'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$sth </span><span style="color: #007700">= </span><span style="color: #0000BB">$dbh</span><span style="color: #007700">-></span><span style="color: #0000BB">prepare</span><span style="color: #007700">(</span><span style="color: #DD0000">'SELECT name, colour, calories<br /> FROM fruit<br /> WHERE calories < ? AND colour = ?'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$sth</span><span style="color: #007700">-></span><span style="color: #0000BB">bindValue</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">$calories</span><span style="color: #007700">, </span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">PARAM_INT</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$sth</span><span style="color: #007700">-></span><span style="color: #0000BB">bindValue</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">, </span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">PARAM_STR</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$sth</span><span style="color: #007700">-></span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
</div>
</div>
<a name="pdostatement.bindvalue.seealso"></a><div class="refsect1 seealso">
<h3 class="title">See Also</h3>
<p class="para">
</p><ul class="simplelist">
<li class="member"><a href="pdo.prepare.php" class="function" rel="rdfs-seeAlso">PDO::prepare()</a> - Prepares a statement for execution and returns a statement object</li>
<li class="member"><a href="pdostatement.execute.php" class="function" rel="rdfs-seeAlso">PDOStatement::execute()</a> - Executes a prepared statement</li>
<li class="member"><a href="pdostatement.bindparam.php" class="function" rel="rdfs-seeAlso">PDOStatement::bindParam()</a> - Binds a parameter to the specified variable name</li>
</ul><p>
</p>
</div>
</div><?php manual_footer(); ?>