reference/sqlite3/sqlite3stmt/bindvalue.xml
855bfee2f3db70d7dbb4c60c7c4a4efa567f1c60
...
...
@@ -1,6 +1,5 @@
1
1
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
-

4
3
<refentry xml:id="sqlite3stmt.bindvalue" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
5
4
<refnamediv>
6
5
<refname>SQLite3Stmt::bindValue</refname>
...
...
@@ -9,15 +8,22 @@
9
8

10
9
<refsect1 role="description">
11
10
&reftitle.description;
12
-
<methodsynopsis>
11
+
<methodsynopsis role="SQLite3Stmt">
13
12
<modifier>public</modifier> <type>bool</type><methodname>SQLite3Stmt::bindValue</methodname>
14
-
<methodparam><type>mixed</type><parameter>sql_param</parameter></methodparam>
13
+
<methodparam><type class="union"><type>string</type><type>int</type></type><parameter>param</parameter></methodparam>
15
14
<methodparam><type>mixed</type><parameter>value</parameter></methodparam>
16
-
<methodparam choice="opt"><type>int</type><parameter>type</parameter></methodparam>
15
+
<methodparam choice="opt"><type>int</type><parameter>type</parameter><initializer><constant>SQLITE3_TEXT</constant></initializer></methodparam>
17
16
</methodsynopsis>
18
17
<para>
19
18
Binds the value of a parameter to a statement variable.
20
19
</para>
20
+
<caution>
21
+
<para>
22
+
Before PHP 7.2.14 and 7.3.0, respectively,
23
+
once the statement has been executed, <methodname>SQLite3Stmt::reset</methodname>
24
+
needs to be called to be able to change the value of bound parameters.
25
+
</para>
26
+
</caution>
21
27
</refsect1>
22
28

23
29
<refsect1 role="parameters">
...
...
@@ -25,11 +31,15 @@
25
31
<para>
26
32
<variablelist>
27
33
<varlistentry>
28
-
<term><parameter>sql_param</parameter></term>
34
+
<term><parameter>param</parameter></term>
29
35
<listitem>
30
36
<para>
31
-
Either a <type>string</type> or an <type>int</type> identifying the statement variable to which the
37
+
Either a <type>string</type> (for named parameters) or an <type>int</type>
38
+
(for positional parameters) identifying the statement variable to which the
32
39
value should be bound.
40
+
If a named parameter does not start with a colon (<literal>:</literal>) or an
41
+
at sign (<literal>@</literal>), a colon (<literal>:</literal>) is automatically preprended.
42
+
Positional parameters start with <literal>1</literal>.
33
43
</para>
34
44
</listitem>
35
45
</varlistentry>
...
...
@@ -49,36 +59,52 @@
49
59
<itemizedlist>
50
60
<listitem>
51
61
<para>
52
-
<literal>SQLITE3_INTEGER</literal>: The value is a signed integer,
62
+
<constant>SQLITE3_INTEGER</constant>: The value is a signed integer,
53
63
stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of
54
64
the value.
55
65
</para>
56
66
</listitem>
57
67
<listitem>
58
68
<para>
59
-
<literal>SQLITE3_FLOAT</literal>: The value is a floating point
69
+
<constant>SQLITE3_FLOAT</constant>: The value is a floating point
60
70
value, stored as an 8-byte IEEE floating point number.
61
71
</para>
62
72
</listitem>
63
73
<listitem>
64
74
<para>
65
-
<literal>SQLITE3_TEXT</literal>: The value is a text string, stored
75
+
<constant>SQLITE3_TEXT</constant>: The value is a text string, stored
66
76
using the database encoding (UTF-8, UTF-16BE or UTF-16-LE).
67
77
</para>
68
78
</listitem>
69
79
<listitem>
70
80
<para>
71
-
<literal>SQLITE3_BLOB</literal>: The value is a blob of data, stored
81
+
<constant>SQLITE3_BLOB</constant>: The value is a blob of data, stored
72
82
exactly as it was input.
73
83
</para>
74
84
</listitem>
75
85
<listitem>
76
86
<para>
77
-
<literal>SQLITE3_NULL</literal>: The value is a NULL value.
87
+
<constant>SQLITE3_NULL</constant>: The value is a NULL value.
78
88
</para>
79
89
</listitem>
80
90
</itemizedlist>
81
91
</para>
92
+
<para>
93
+
As of PHP 7.0.7, if <parameter>type</parameter> is omitted, it is automatically
94
+
detected from the type of the <parameter>value</parameter>: <type>bool</type>
95
+
and <type>int</type> are treated as <constant>SQLITE3_INTEGER</constant>,
96
+
<type>float</type> as <constant>SQLITE3_FLOAT</constant>, <type>null</type>
97
+
as <constant>SQLITE3_NULL</constant> and all others as <constant>SQLITE3_TEXT</constant>.
98
+
Formerly, if <parameter>type</parameter> has been omitted, it has defaulted
99
+
to <constant>SQLITE3_TEXT</constant>.
100
+
</para>
101
+
<note>
102
+
<para>
103
+
If <parameter>value</parameter> is &null;, it is always treated as
104
+
<constant>SQLITE3_NULL</constant>, regardless of the given
105
+
<parameter>type</parameter>.
106
+
</para>
107
+
</note>
82
108
</listitem>
83
109
</varlistentry>
84
110
</variablelist>
...
...
@@ -89,11 +115,33 @@
89
115
<refsect1 role="returnvalues">
90
116
&reftitle.returnvalues;
91
117
<para>
92
-
Returns &true; if the value is bound to the statement variable, &false;
93
-
on failure.
118
+
Returns &true; if the value is bound to the statement variable, &return.falseforfailure;.
94
119
</para>
95
120
</refsect1>
96
121

122
+
<refsect1 role="changelog">
123
+
&reftitle.changelog;
124
+
<informaltable>
125
+
<tgroup cols="2">
126
+
<thead>
127
+
<row>
128
+
<entry>&Version;</entry>
129
+
<entry>&Description;</entry>
130
+
</row>
131
+
</thead>
132
+
<tbody>
133
+
<row>
134
+
<entry>7.4.0</entry>
135
+
<entry>
136
+
<parameter>param</parameter> now also supports the <literal>@param</literal>
137
+
notation.
138
+
</entry>
139
+
</row>
140
+
</tbody>
141
+
</tgroup>
142
+
</informaltable>
143
+
</refsect1>
144
+

97
145
<refsect1 role="examples">
98
146
&reftitle.examples;
99
147
<para>
...
...
@@ -102,8 +150,7 @@
102
150
<programlisting role="php">
103
151
<![CDATA[
104
152
<?php
105
-
unlink('mysqlitedb.db');
106
-
$db = new SQLite3('mysqlitedb.db');
153
+
$db = new SQLite3(':memory:');
107
154

108
155
$db->exec('CREATE TABLE foo (id INTEGER, bar STRING)');
109
156
$db->exec("INSERT INTO foo (id, bar) VALUES (1, 'This is a test')");
...
...
@@ -112,16 +159,32 @@ $stmt = $db->prepare('SELECT bar FROM foo WHERE id=:id');
112
159
$stmt->bindValue(':id', 1, SQLITE3_INTEGER);
113
160

114
161
$result = $stmt->execute();
115
-
var_dump($result->fetchArray());
162
+
var_dump($result->fetchArray(SQLITE3_ASSOC));
116
163
?>
117
164
]]>
118
165
</programlisting>
166
+
&example.outputs;
167
+
<screen role="php">
168
+
<![CDATA[
169
+
array(1) {
170
+
["bar"]=>
171
+
string(14) "This is a test"
172
+
}
173
+
]]>
174
+
</screen>
119
175
</example>
120
176
</para>
121
177
</refsect1>
122
178

123
-
</refentry>
179
+
<refsect1 role="seealso">
180
+
&reftitle.seealso;
181
+
<simplelist>
182
+
<member><methodname>SQLite3Stmt::bindParam</methodname></member>
183
+
<member><methodname>SQLite3::prepare</methodname></member>
184
+
</simplelist>
185
+
</refsect1>
124
186

187
+
</refentry>
125
188
<!-- Keep this comment at the end of the file
126
189
Local variables:
127
190
mode: sgml
128
191