reference/pdo/pdostatement/execute.xml
082ddc19f53e6e254010de1a1fbbe485ff744ec1
...
...
@@ -9,22 +9,21 @@
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::execute</methodname>
14
-
<methodparam choice="opt"><type>array</type><parameter>input_parameters</parameter></methodparam>
14
+
<methodparam choice="opt"><type class="union"><type>array</type><type>null</type></type><parameter>params</parameter><initializer>&null;</initializer></methodparam>
15
15
</methodsynopsis>
16
16
<para>
17
17
Execute the <link linkend="pdo.prepared-statements">prepared
18
-
statement</link>. If the prepared statement included parameter markers, you
19
-
must either:
18
+
statement</link>. If the prepared statement included parameter markers, either:
20
19
<itemizedlist>
21
-
<listitem><para>call <function>PDOStatement::bindParam</function> and/or
22
-
<function>PDOStatement::bindValue</function> to bind either variables or
20
+
<listitem><para><methodname>PDOStatement::bindParam</methodname> and/or
21
+
<methodname>PDOStatement::bindValue</methodname> has to be called to bind either variables or
23
22
values (respectively) to the parameter markers. Bound variables pass
24
23
their value as input and receive the output value, if any, of their
25
24
associated parameter markers</para></listitem>
26
25
<listitem>
27
-
<para>or pass an array of input-only parameter values</para>
26
+
<para>or an array of input-only parameter values has to be passed</para>
28
27
</listitem>
29
28
</itemizedlist>
30
29
</para>
...
...
@@ -35,7 +34,7 @@
35
34
<para>
36
35
<variablelist>
37
36
<varlistentry>
38
-
<term><parameter>input_parameters</parameter></term>
37
+
<term><parameter>params</parameter></term>
39
38
<listitem>
40
39
<para>
41
40
An array of values with as many elements as there are bound
...
...
@@ -43,13 +42,13 @@
43
42
All values are treated as <constant>PDO::PARAM_STR</constant>.
44
43
</para>
45
44
<para>
46
-
You cannot bind multiple values to a single parameter; for example,
47
-
you cannot bind two values to a single named parameter in an IN()
45
+
Multiple values cannot be bound to a single parameter; for example,
46
+
it is not allowed to bind two values to a single named parameter in an IN()
48
47
clause.
49
48
</para>
50
49
<para>
51
-
You cannot bind more values than specified; if more keys exist in
52
-
<parameter>input_parameters</parameter> than in the SQL specified
50
+
Binding more values than specified is not possible; if more keys exist in
51
+
<parameter>params</parameter> than in the SQL specified
53
52
in the <methodname>PDO::prepare</methodname>, then the statement will
54
53
fail and an error is emitted.
55
54
</para>
...
...
@@ -66,29 +65,9 @@
66
65
</para>
67
66
</refsect1>
68
67

69
-
<refsect1 role="changelog">
70
-
&reftitle.changelog;
71
-
<para>
72
-
<informaltable>
73
-
<tgroup cols="2">
74
-
<thead>
75
-
<row>
76
-
<entry>&Version;</entry>
77
-
<entry>&Description;</entry>
78
-
</row>
79
-
</thead>
80
-
<tbody>
81
-
<row>
82
-
<entry>5.2.0</entry>
83
-
<entry>
84
-
The keys from <parameter>input_parameters</parameter> must match the ones
85
-
declared in the SQL. Before PHP 5.2.0 this was silently ignored.
86
-
</entry>
87
-
</row>
88
-
</tbody>
89
-
</tgroup>
90
-
</informaltable>
91
-
</para>
68
+
<refsect1 role="errors">
69
+
&reftitle.errors;
70
+
&pdo.errors;
92
71
</refsect1>
93
72

94
73
<refsect1 role="examples">
...
...
@@ -103,15 +82,16 @@ $colour = 'gre';
103
82
$sth = $dbh->prepare('SELECT name, colour, calories
104
83
FROM fruit
105
84
WHERE calories < :calories AND colour LIKE :colour');
106
-
$sth->bindParam(':calories', $calories, PDO::PARAM_INT);
107
-
$sth->bindValue(':colour', "%{$colour}%");
85
+
$sth->bindParam('calories', $calories, PDO::PARAM_INT);
86
+
/* Names can be prefixed with colons ":" too (optional) */
87
+
$sth->bindValue(':colour', "%$colour%");
108
88
$sth->execute();
109
89
?>
110
90
]]>
111
91
</programlisting>
112
92
</example>
113
93

114
-
<example><title>Execute a prepared statement with an array of insert values (named parameters)</title>
94
+
<example><title>Execute a prepared statement with an array of named values</title>
115
95
<programlisting role="php">
116
96
<![CDATA[
117
97
<?php
...
...
@@ -121,13 +101,15 @@ $colour = 'red';
121
101
$sth = $dbh->prepare('SELECT name, colour, calories
122
102
FROM fruit
123
103
WHERE calories < :calories AND colour = :colour');
104
+
$sth->execute(array('calories' => $calories, 'colour' => $colour));
105
+
/* Array keys can be prefixed with colons ":" too (optional) */
124
106
$sth->execute(array(':calories' => $calories, ':colour' => $colour));
125
107
?>
126
108
]]>
127
109
</programlisting>
128
110
</example>
129
111

130
-
<example><title>Execute a prepared statement with an array of insert values (placeholders)</title>
112
+
<example><title>Execute a prepared statement with an array of positional values</title>
131
113
<programlisting role="php">
132
114
<![CDATA[
133
115
<?php
...
...
@@ -143,7 +125,7 @@ $sth->execute(array($calories, $colour));
143
125
</programlisting>
144
126
</example>
145
127

146
-
<example><title>Execute a prepared statement with question mark placeholders</title>
128
+
<example><title>Execute a prepared statement with variables bound to positional placeholders</title>
147
129
<programlisting role="php">
148
130
<![CDATA[
149
131
<?php
...
...
@@ -200,17 +182,16 @@ $sth->execute($params);
200
182
&reftitle.seealso;
201
183
<para>
202
184
<simplelist>
203
-
<member><function>PDO::prepare</function></member>
204
-
<member><function>PDOStatement::bindParam</function></member>
205
-
<member><function>PDOStatement::fetch</function></member>
206
-
<member><function>PDOStatement::fetchAll</function></member>
207
-
<member><function>PDOStatement::fetchColumn</function></member>
185
+
<member><methodname>PDO::prepare</methodname></member>
186
+
<member><methodname>PDOStatement::bindParam</methodname></member>
187
+
<member><methodname>PDOStatement::fetch</methodname></member>
188
+
<member><methodname>PDOStatement::fetchAll</methodname></member>
189
+
<member><methodname>PDOStatement::fetchColumn</methodname></member>
208
190
</simplelist>
209
191
</para>
210
192
</refsect1>
211
193

212
194
</refentry>
213
-

214
195
<!-- Keep this comment at the end of the file
215
196
Local variables:
216
197
mode: sgml
217
198