<?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 => 'zh', ), 'this' => array ( 0 => 'sqlite3stmt.bindvalue.php', 1 => 'SQLite3Stmt::bindValue', 2 => 'Binds the value of a parameter to a statement variable', ), 'up' => array ( 0 => 'class.sqlite3stmt.php', 1 => 'SQLite3Stmt', ), 'prev' => array ( 0 => 'sqlite3stmt.bindparam.php', 1 => 'SQLite3Stmt::bindParam', ), 'next' => array ( 0 => 'sqlite3stmt.clear.php', 1 => 'SQLite3Stmt::clear', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/sqlite3/sqlite3stmt/bindvalue.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?> <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, PHP 8)</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">说明</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="methodname"><strong>SQLite3Stmt::bindValue</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">$value</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"> Binds the value of a parameter to a statement variable. </p> <div class="caution"><strong class="caution">警告</strong> <p class="para"> Before PHP 7.2.14 and 7.3.0, respectively, once the statement has been executed, <span class="methodname"><a href="sqlite3stmt.reset.php" class="methodname">SQLite3Stmt::reset()</a></span> needs to be called to be able to change the value of bound parameters. </p> </div> </div> <div class="refsect1 parameters" id="refsect1-sqlite3stmt.bindvalue-parameters"> <h3 class="title">参数</h3> <p class="para"> <dl> <dt><code class="parameter">param</code></dt> <dd> <p class="para"> Either a <span class="type"><a href="language.types.string.php" class="type string">string</a></span> (for named parameters) or an <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> (for positional parameters) identifying the statement variable to which the value should be bound. If a named parameter does not start with a colon (<code class="literal">:</code>) or an at sign (<code class="literal">@</code>), a colon (<code class="literal">:</code>) is automatically preprended. Positional parameters start with <code class="literal">1</code>. </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><a href="sqlite3.constants.php#constant.sqlite3-integer">SQLITE3_INTEGER</a></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><a href="sqlite3.constants.php#constant.sqlite3-float">SQLITE3_FLOAT</a></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><a href="sqlite3.constants.php#constant.sqlite3-text">SQLITE3_TEXT</a></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><a href="sqlite3.constants.php#constant.sqlite3-blob">SQLITE3_BLOB</a></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><a href="sqlite3.constants.php#constant.sqlite3-null">SQLITE3_NULL</a></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.php" class="type bool">bool</a></span> and <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> are treated as <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> as <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> as <strong><code><a href="sqlite3.constants.php#constant.sqlite3-null">SQLITE3_NULL</a></code></strong> and all others as <strong><code><a href="sqlite3.constants.php#constant.sqlite3-text">SQLITE3_TEXT</a></code></strong>. Formerly, if <code class="parameter">type</code> has been omitted, it has defaulted to <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"> If <code class="parameter">value</code> is <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>, it is always treated as <strong><code><a href="sqlite3.constants.php#constant.sqlite3-null">SQLITE3_NULL</a></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">返回值</h3> <p class="para"> Returns <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> if the value is bound to the statement variable, 或者在失败时返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>. </p> </div> <div class="refsect1 changelog" id="refsect1-sqlite3stmt.bindvalue-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> now also supports the <code class="literal">@param</code> notation. </td> </tr> </tbody> </table> </div> <div class="refsect1 examples" id="refsect1-sqlite3stmt.bindvalue-examples"> <h3 class="title">示例</h3> <p class="para"> <div class="example" id="example-2122"> <p><strong>示例 #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>以上示例会输出:</p></div> <div class="example-contents screen"> <div class="examplescode"><pre class="examplescode">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">参见</h3> <ul class="simplelist"> <li><span class="methodname"><a href="sqlite3stmt.bindparam.php" class="methodname" rel="rdfs-seeAlso">SQLite3Stmt::bindParam()</a> - Binds a parameter to a statement variable</span></li> <li><span class="methodname"><a href="sqlite3.prepare.php" class="methodname" rel="rdfs-seeAlso">SQLite3::prepare()</a> - Prepares an SQL statement for execution</span></li> </ul> </div> </div><?php manual_footer($setup); ?>