reference/pdo/pdostatement/bindparam.xml
28529d3539b850e870e3aa97570f4db0e53daa03
...
...
@@ -9,24 +9,25 @@
9
9
</refnamediv>
10
10
<refsect1 role="description">
11
11
&reftitle.description;
12
-
<methodsynopsis>
12
+
<methodsynopsis role="PDOStatement">
13
13
<modifier>public</modifier> <type>bool</type><methodname>PDOStatement::bindParam</methodname>
14
-
<methodparam><type>mixed</type><parameter>parameter</parameter></methodparam>
15
-
<methodparam><type>mixed</type><parameter role="reference">variable</parameter></methodparam>
16
-
<methodparam choice="opt"><type>int</type><parameter>data_type</parameter><initializer>PDO::PARAM_STR</initializer></methodparam>
17
-
<methodparam choice="opt"><type>int</type><parameter>length</parameter></methodparam>
18
-
<methodparam choice="opt"><type>mixed</type><parameter>driver_options</parameter></methodparam>
14
+
<methodparam><type class="union"><type>string</type><type>int</type></type><parameter>param</parameter></methodparam>
15
+
<methodparam><type>mixed</type><parameter role="reference">var</parameter></methodparam>
16
+
<methodparam choice="opt"><type>int</type><parameter>type</parameter><initializer>PDO::PARAM_STR</initializer></methodparam>
17
+
<methodparam choice="opt"><type>int</type><parameter>maxLength</parameter><initializer>0</initializer></methodparam>
18
+
<methodparam choice="opt"><type>mixed</type><parameter>driverOptions</parameter><initializer>&null;</initializer></methodparam>
19
19
</methodsynopsis>
20
20
<para>
21
21
Binds a PHP variable to a corresponding named or question mark placeholder
22
22
in the SQL statement that was used to prepare the statement. Unlike
23
-
<function>PDOStatement::bindValue</function>, the variable is bound as a
23
+
<methodname>PDOStatement::bindValue</methodname>, the variable is bound as a
24
24
reference and will only be evaluated at the time that
25
-
<function>PDOStatement::execute</function> is called.
25
+
<methodname>PDOStatement::execute</methodname> is called.
26
26
</para>
27
27
<para>
28
28
Most parameters are input parameters, that is, parameters that are used
29
-
in a read-only fashion to build up the query. Some drivers support the
29
+
in a read-only fashion to build up the query (but may nonetheless be cast
30
+
according to <parameter>type</parameter>). Some drivers support the
30
31
invocation of stored procedures that return data as output parameters,
31
32
and some also as input/output parameters that both send in data and are
32
33
updated to receive it.
...
...
@@ -39,7 +40,7 @@
39
40
<para>
40
41
<variablelist>
41
42
<varlistentry>
42
-
<term><parameter>parameter</parameter></term>
43
+
<term><parameter>param</parameter></term>
43
44
<listitem>
44
45
<para>
45
46
Parameter identifier. For a prepared statement using named
...
...
@@ -51,7 +52,7 @@
51
52
</listitem>
52
53
</varlistentry>
53
54
<varlistentry>
54
-
<term><parameter>variable</parameter></term>
55
+
<term><parameter>var</parameter></term>
55
56
<listitem>
56
57
<para>
57
58
Name of the PHP variable to bind to the SQL statement parameter.
...
...
@@ -59,30 +60,30 @@
59
60
</listitem>
60
61
</varlistentry>
61
62
<varlistentry>
62
-
<term><parameter>data_type</parameter></term>
63
+
<term><parameter>type</parameter></term>
63
64
<listitem>
64
65
<para>
65
-
Explicit data type for the parameter using the <link
66
-
linkend="pdo.constants"><literal>PDO::PARAM_*</literal>
66
+
Explicit data type for the parameter using the <link linkend="pdo.constants"><literal>PDO::PARAM_*</literal>
67
67
constants</link>.
68
68
To return an INOUT parameter from a stored procedure,
69
-
use the bitwise OR operator to set the PDO::PARAM_INPUT_OUTPUT bits
70
-
for the <parameter>data_type</parameter> parameter.
69
+
use the bitwise OR operator to set the <constant>PDO::PARAM_INPUT_OUTPUT</constant> bits
70
+
for the <parameter>type</parameter> parameter.
71
71
</para>
72
72
</listitem>
73
73
</varlistentry>
74
74
<varlistentry>
75
-
<term><parameter>length</parameter></term>
75
+
<term><parameter>maxLength</parameter></term>
76
76
<listitem>
77
77
<para>
78
78
Length of the data type. To indicate that a parameter is an OUT
79
79
parameter from a stored procedure, you must explicitly set the
80
80
length.
81
+
Meaningful only when <parameter>type</parameter> parameter is <constant>PDO::PARAM_INPUT_OUTPUT</constant>.
81
82
</para>
82
83
</listitem>
83
84
</varlistentry>
84
85
<varlistentry>
85
-
<term><parameter>driver_options</parameter></term>
86
+
<term><parameter>driverOptions</parameter></term>
86
87
<listitem>
87
88
<para>
88
89
...
...
@@ -100,6 +101,11 @@
100
101
</para>
101
102
</refsect1>
102
103

104
+
<refsect1 role="errors">
105
+
&reftitle.errors;
106
+
&pdo.errors;
107
+
</refsect1>
108
+

103
109
<refsect1 role="examples">
104
110
&reftitle.examples;
105
111
<example><title>Execute a prepared statement with named placeholders</title>
...
...
@@ -112,8 +118,9 @@ $colour = 'red';
112
118
$sth = $dbh->prepare('SELECT name, colour, calories
113
119
FROM fruit
114
120
WHERE calories < :calories AND colour = :colour');
115
-
$sth->bindParam(':calories', $calories, PDO::PARAM_INT);
116
-
$sth->bindParam(':colour', $colour, PDO::PARAM_STR, 12);
121
+
$sth->bindParam('calories', $calories, PDO::PARAM_INT);
122
+
/* Names can be prefixed with colons ":" too (optional) */
123
+
$sth->bindParam(':colour', $colour, PDO::PARAM_STR);
117
124
$sth->execute();
118
125
?>
119
126
]]>
...
...
@@ -131,7 +138,7 @@ $sth = $dbh->prepare('SELECT name, colour, calories
131
138
FROM fruit
132
139
WHERE calories < ? AND colour = ?');
133
140
$sth->bindParam(1, $calories, PDO::PARAM_INT);
134
-
$sth->bindParam(2, $colour, PDO::PARAM_STR, 12);
141
+
$sth->bindParam(2, $colour, PDO::PARAM_STR);
135
142
$sth->execute();
136
143
?>
137
144
]]>
...
...
@@ -169,7 +176,7 @@ $colour = 'red';
169
176
$sth = $dbh->prepare('CALL puree_fruit(?)');
170
177
$sth->bindParam(1, $colour, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 12);
171
178
$sth->execute();
172
-
print("After pureeing fruit, the colour is: $colour");
179
+
print "After pureeing fruit, the colour is: $colour";
173
180
?>
174
181
]]>
175
182
</programlisting>
...
...
@@ -181,15 +188,14 @@ print("After pureeing fruit, the colour is: $colour");
181
188
&reftitle.seealso;
182
189
<para>
183
190
<simplelist>
184
-
<member><function>PDO::prepare</function></member>
185
-
<member><function>PDOStatement::execute</function></member>
186
-
<member><function>PDOStatement::bindValue</function></member>
191
+
<member><methodname>PDO::prepare</methodname></member>
192
+
<member><methodname>PDOStatement::execute</methodname></member>
193
+
<member><methodname>PDOStatement::bindValue</methodname></member>
187
194
</simplelist>
188
195
</para>
189
196

190
197
</refsect1>
191
198
</refentry>
192
-

193
199
<!-- Keep this comment at the end of the file
194
200
Local variables:
195
201
mode: sgml
196
202