<!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>Binds the value of a parameter to a statement variable</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="sqlite3stmt.bindparam.html">SQLite3Stmt::bindParam</a></div> <div class="next" style="text-align: right; float: right;"><a href="sqlite3stmt.clear.html">SQLite3Stmt::clear</a></div> <div class="up"><a href="class.sqlite3stmt.html">SQLite3Stmt</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="sqlite3stmt.bindvalue" class="refentry"> <div class="refnamediv"> <h1 class="refname">SQLite3Stmt::bindValue</h1> <p class="verinfo">(PHP 5 >= 5.3.0, PHP 7)</p><p class="refpurpose"><span class="refname">SQLite3Stmt::bindValue</span> — <span class="dc-title">Binds the value of a parameter to a statement variable</span></p> </div> <div class="refsect1 description" id="refsect1-sqlite3stmt.bindvalue-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">bool</span> <span class="methodname"><strong>SQLite3Stmt::bindValue</strong></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">$sql_param</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">$value</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$type</code></span> ] )</div> <p class="para rdfs-comment"> Binds the value of a parameter to a statement variable. </p> </div> <div class="refsect1 parameters" id="refsect1-sqlite3stmt.bindvalue-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <code class="parameter">sql_param</code></dt> <dd> <p class="para"> Either a <span class="type"><a href="language.types.string.html" class="type string">string</a></span> or an <span class="type"><a href="language.types.integer.html" class="type int">int</a></span> identifying the statement variable to which the value should be bound. </p> </dd> <dt> <code class="parameter">value</code></dt> <dd> <p class="para"> The value to bind to a statement variable. </p> </dd> <dt> <code class="parameter">type</code></dt> <dd> <p class="para"> The data type of the value to bind. <ul class="itemizedlist"> <li class="listitem"> <p class="para"> <strong><code>SQLITE3_INTEGER</code></strong>: The value is a signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value. </p> </li> <li class="listitem"> <p class="para"> <strong><code>SQLITE3_FLOAT</code></strong>: The value is a floating point value, stored as an 8-byte IEEE floating point number. </p> </li> <li class="listitem"> <p class="para"> <strong><code>SQLITE3_TEXT</code></strong>: The value is a text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-16-LE). </p> </li> <li class="listitem"> <p class="para"> <strong><code>SQLITE3_BLOB</code></strong>: The value is a blob of data, stored exactly as it was input. </p> </li> <li class="listitem"> <p class="para"> <strong><code>SQLITE3_NULL</code></strong>: The value is a NULL value. </p> </li> </ul> </p> <p class="para"> As of PHP 7.0.7, if <code class="parameter">type</code> is omitted, it is automatically detected from the type of the <code class="parameter">value</code>: <span class="type"><a href="language.types.boolean.html" class="type boolean">boolean</a></span> and <span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span> are treated as <strong><code>SQLITE3_INTEGER</code></strong>, <span class="type"><a href="language.types.float.html" class="type float">float</a></span> as <strong><code>SQLITE3_FLOAT</code></strong>, <span class="type"><a href="language.types.null.html" class="type null">null</a></span> as <strong><code>SQLITE3_NULL</code></strong> and all others as <strong><code>SQLITE3_TEXT</code></strong>. Formerly, if <code class="parameter">type</code> has been omitted, it has defaulted to <strong><code>SQLITE3_TEXT</code></strong>. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> If <code class="parameter">value</code> is <strong><code>NULL</code></strong>, it is always treated as <strong><code>SQLITE3_NULL</code></strong>, regardless of the given <code class="parameter">type</code>. </p> </p></blockquote> </dd> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-sqlite3stmt.bindvalue-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <strong><code>TRUE</code></strong> if the value is bound to the statement variable, <strong><code>FALSE</code></strong> on failure. </p> </div> <div class="refsect1 examples" id="refsect1-sqlite3stmt.bindvalue-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2651"> <p><strong>Example #1 <span class="function"><strong>SQLite3Stmt::bindValue()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?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 /><br /></span><span style="color: #0000BB">$db</span><span style="color: #007700">-></span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">'CREATE TABLE foo (id INTEGER, bar STRING)'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$db</span><span style="color: #007700">-></span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">"INSERT INTO foo (id, bar) VALUES (1, 'This is a test')"</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">-></span><span style="color: #0000BB">prepare</span><span style="color: #007700">(</span><span style="color: #DD0000">'SELECT bar FROM foo WHERE id=:id'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-></span><span style="color: #0000BB">bindValue</span><span style="color: #007700">(</span><span style="color: #DD0000">':id'</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">SQLITE3_INTEGER</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-></span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">-></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">?></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> array(1) { ["bar"]=> string(14) "This is a test" } </pre></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-sqlite3stmt.bindvalue-seealso"> <h3 class="title">See Also</h3> <ul class="simplelist"> <li class="member"><span class="methodname"><a href="sqlite3stmt.bindparam.html" class="methodname" rel="rdfs-seeAlso">SQLite3Stmt::bindParam()</a> - Binds a parameter to a statement variable</span></li> <li class="member"><span class="methodname"><a href="sqlite3.prepare.html" class="methodname" rel="rdfs-seeAlso">SQLite3::prepare()</a> - Prepares an SQL statement for execution</span></li> </ul> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="sqlite3stmt.bindparam.html">SQLite3Stmt::bindParam</a></div> <div class="next" style="text-align: right; float: right;"><a href="sqlite3stmt.clear.html">SQLite3Stmt::clear</a></div> <div class="up"><a href="class.sqlite3stmt.html">SQLite3Stmt</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>