reference/mysqli/mysqli_stmt/execute.xml
ec946465e5ee9dc4dc19f1a28510697066a19eac
...
...
@@ -10,14 +10,15 @@
10
10
<refsect1 role="description">
11
11
&reftitle.description;
12
12
<para>&style.oop;</para>
13
-
<methodsynopsis role="oop">
13
+
<methodsynopsis role="mysqli_stmt">
14
14
<modifier>public</modifier> <type>bool</type><methodname>mysqli_stmt::execute</methodname>
15
-
<void/>
15
+
<methodparam choice="opt"><type class="union"><type>array</type><type>null</type></type><parameter>params</parameter><initializer>&null;</initializer></methodparam>
16
16
</methodsynopsis>
17
17
<para>&style.procedural;</para>
18
-
<methodsynopsis role="procedural">
18
+
<methodsynopsis>
19
19
<type>bool</type><methodname>mysqli_stmt_execute</methodname>
20
20
<methodparam><type>mysqli_stmt</type><parameter>statement</parameter></methodparam>
21
+
<methodparam choice="opt"><type class="union"><type>array</type><type>null</type></type><parameter>params</parameter><initializer>&null;</initializer></methodparam>
21
22
</methodsynopsis>
22
23
<para>
23
24
Executes previously prepared statement. The statement must be successfully
...
...
@@ -30,8 +31,10 @@
30
31
If the statement is <literal>UPDATE</literal>, <literal>DELETE</literal>,
31
32
or <literal>INSERT</literal>, the total number of affected rows can be
32
33
determined by using the <function>mysqli_stmt_affected_rows</function>
33
-
function. Likewise, if the query yields a result set the
34
-
<function>mysqli_stmt_fetch</function> function is used.
34
+
function. If the query yields a result set, it can be fetched using
35
+
<function>mysqli_stmt_get_result</function> function or by fetching it
36
+
row by row directly from the statement using
37
+
<function>mysqli_stmt_fetch</function> function.
35
38
</para>
36
39
</refsect1>
37
40

...
...
@@ -40,6 +43,14 @@
40
43
<para>
41
44
<variablelist>
42
45
&mysqli.stmt.description;
46
+
<varlistentry>
47
+
<term><parameter>params</parameter></term>
48
+
<listitem>
49
+
<para>
50
+
An optional list &array; with as many elements as there are bound parameters in the SQL statement being executed. Each value is treated as a &string;.
51
+
</para>
52
+
</listitem>
53
+
</varlistentry>
43
54
</variablelist>
44
55
</para>
45
56
</refsect1>
...
...
@@ -51,10 +62,37 @@
51
62
</para>
52
63
</refsect1>
53
64

65
+
<refsect1 role="errors">
66
+
&reftitle.errors;
67
+
&mysqli.conditionalexception;
68
+
</refsect1>
69
+

70
+
<refsect1 role="changelog">
71
+
&reftitle.changelog;
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>8.1.0</entry>
83
+
<entry>
84
+
The optional <parameter>params</parameter> parameter has been added.
85
+
</entry>
86
+
</row>
87
+
</tbody>
88
+
</tgroup>
89
+
</informaltable>
90
+
</refsect1>
91
+

54
92
<refsect1 role="examples">
55
93
&reftitle.examples;
56
94
<example>
57
-
<title><methodname>mysqli_stmt::execute</methodname> example</title>
95
+
<title>Execute a prepared statement with bound variables</title>
58
96
<para>&style.oop;</para>
59
97
<programlisting role="php">
60
98
<![CDATA[
...
...
@@ -63,7 +101,7 @@
63
101
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
64
102
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
65
103

66
-
$mysqli->query("CREATE TABLE myCity LIKE City");
104
+
$mysqli->query("CREATE TEMPORARY TABLE myCity LIKE City");
67
105

68
106
/* Prepare an insert statement */
69
107
$stmt = $mysqli->prepare("INSERT INTO myCity (Name, CountryCode, District) VALUES (?,?,?)");
...
...
@@ -85,15 +123,12 @@ $val3 = 'Aquitaine';
85
123
/* Execute the statement */
86
124
$stmt->execute();
87
125

88
-
/* retrieve all rows from myCity */
126
+
/* Retrieve all rows from myCity */
89
127
$query = "SELECT Name, CountryCode, District FROM myCity";
90
128
$result = $mysqli->query($query);
91
129
while ($row = $result->fetch_row()) {
92
130
printf("%s (%s,%s)\n", $row[0], $row[1], $row[2]);
93
131
}
94
-

95
-
/* remove table */
96
-
$mysqli->query("DROP TABLE myCity");
97
132
]]>
98
133
</programlisting>
99
134
<para>&style.procedural;</para>
...
...
@@ -104,7 +139,7 @@ $mysqli->query("DROP TABLE myCity");
104
139
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
105
140
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
106
141

107
-
mysqli_query($link, "CREATE TABLE myCity LIKE City");
142
+
mysqli_query($link, "CREATE TEMPORARY TABLE myCity LIKE City");
108
143

109
144
/* Prepare an insert statement */
110
145
$stmt = mysqli_prepare($link, "INSERT INTO myCity (Name, CountryCode, District) VALUES (?,?,?)");
...
...
@@ -126,15 +161,12 @@ $val3 = 'Aquitaine';
126
161
/* Execute the statement */
127
162
mysqli_stmt_execute($stmt);
128
163

129
-
/* retrieve all rows from myCity */
164
+
/* Retrieve all rows from myCity */
130
165
$query = "SELECT Name, CountryCode, District FROM myCity";
131
166
$result = mysqli_query($link, $query);
132
167
while ($row = mysqli_fetch_row($result)) {
133
168
printf("%s (%s,%s)\n", $row[0], $row[1], $row[2]);
134
169
}
135
-

136
-
/* remove table */
137
-
mysqli_query($link, "DROP TABLE myCity");
138
170
]]>
139
171
</programlisting>
140
172
&examples.outputs;
...
...
@@ -145,12 +177,70 @@ Bordeaux (FRA,Aquitaine)
145
177
]]>
146
178
</screen>
147
179
</example>
180
+
<example>
181
+
<title>Execute a prepared statement with an array of values</title>
182
+
<para>&style.oop;</para>
183
+
<programlisting role="php">
184
+
<![CDATA[
185
+
<?php
186
+

187
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
188
+
$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'world');
189
+

190
+
$mysqli->query('CREATE TEMPORARY TABLE myCity LIKE City');
191
+

192
+
/* Prepare an insert statement */
193
+
$stmt = $mysqli->prepare('INSERT INTO myCity (Name, CountryCode, District) VALUES (?,?,?)');
194
+

195
+
/* Execute the statement */
196
+
$stmt->execute(['Stuttgart', 'DEU', 'Baden-Wuerttemberg']);
197
+

198
+
/* Retrieve all rows from myCity */
199
+
$query = 'SELECT Name, CountryCode, District FROM myCity';
200
+
$result = $mysqli->query($query);
201
+
while ($row = $result->fetch_row()) {
202
+
printf("%s (%s,%s)\n", $row[0], $row[1], $row[2]);
203
+
}
204
+
]]>
205
+
</programlisting>
206
+
<para>&style.procedural;</para>
207
+
<programlisting role="php">
208
+
<![CDATA[
209
+
<?php
210
+

211
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
212
+
$link = mysqli_connect('localhost', 'my_user', 'my_password', 'world');
213
+

214
+
mysqli_query($link, 'CREATE TEMPORARY TABLE myCity LIKE City');
215
+

216
+
/* Prepare an insert statement */
217
+
$stmt = mysqli_prepare($link, 'INSERT INTO myCity (Name, CountryCode, District) VALUES (?,?,?)');
218
+

219
+
/* Execute the statement */
220
+
mysqli_stmt_execute($stmt, ['Stuttgart', 'DEU', 'Baden-Wuerttemberg']);
221
+

222
+
/* Retrieve all rows from myCity */
223
+
$query = 'SELECT Name, CountryCode, District FROM myCity';
224
+
$result = mysqli_query($link, $query);
225
+
while ($row = mysqli_fetch_row($result)) {
226
+
printf("%s (%s,%s)\n", $row[0], $row[1], $row[2]);
227
+
}
228
+
]]>
229
+
</programlisting>
230
+
&examples.outputs;
231
+
<screen>
232
+
<![CDATA[
233
+
Stuttgart (DEU,Baden-Wuerttemberg)
234
+
]]>
235
+
</screen>
236
+
</example>
148
237
</refsect1>
149
238

150
239
<refsect1 role="seealso">
151
240
&reftitle.seealso;
152
241
<para>
153
242
<simplelist>
243
+
<member><function>mysqli_execute_query</function></member>
154
244
<member><function>mysqli_prepare</function></member>
155
245
<member><function>mysqli_stmt_bind_param</function></member>
156
246
<member><function>mysqli_stmt_get_result</function></member>
157
247