reference/pdo/pdostatement/bindparam.xml
28529d3539b850e870e3aa97570f4db0e53daa03
...
...
@@ -1,4 +1,4 @@
1
-
<?xml version="1.0" encoding="UTF-8"?>
1
+
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
3
<refentry xml:id="pdostatement.bindparam" xmlns="http://docbook.org/ns/docbook">
4
4
<refnamediv>
...
...
@@ -9,24 +9,25 @@
9
9
</refnamediv>
10
10
<refsect1 role="description">
11
11
&reftitle.description;
12
-
<methodsynopsis>
13
-
<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>
12
+
<methodsynopsis role="PDOStatement">
13
+
<modifier>public</modifier> <type>bool</type><methodname>PDOStatement::bindParam</methodname>
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,29 +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 PDO::PARAM_*
66
-
constants.
66
+
Explicit data type for the parameter using the <link linkend="pdo.constants"><literal>PDO::PARAM_*</literal>
67
+
constants</link>.
67
68
To return an INOUT parameter from a stored procedure,
68
-
use the bitwise OR operator to set the PDO::PARAM_INPUT_OUTPUT bits
69
-
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.
70
71
</para>
71
72
</listitem>
72
73
</varlistentry>
73
74
<varlistentry>
74
-
<term><parameter>length</parameter></term>
75
+
<term><parameter>maxLength</parameter></term>
75
76
<listitem>
76
77
<para>
77
78
Length of the data type. To indicate that a parameter is an OUT
78
79
parameter from a stored procedure, you must explicitly set the
79
80
length.
81
+
Meaningful only when <parameter>type</parameter> parameter is <constant>PDO::PARAM_INPUT_OUTPUT</constant>.
80
82
</para>
81
83
</listitem>
82
84
</varlistentry>
83
85
<varlistentry>
84
-
<term><parameter>driver_options</parameter></term>
86
+
<term><parameter>driverOptions</parameter></term>
85
87
<listitem>
86
88
<para>
87
89
...
...
@@ -99,6 +101,11 @@
99
101
</para>
100
102
</refsect1>
101
103

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

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

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

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