reference/mysqli/mysqli_stmt/bind-param.xml
63b99082ef83eade08151f8cb528246fded81db9
...
...
@@ -10,23 +10,23 @@
10
10
<refsect1 role="description">
11
11
&reftitle.description;
12
12
<para>&style.oop;</para>
13
-
<methodsynopsis role="oop">
14
-
<type>bool</type><methodname>mysqli_stmt::bind_param</methodname>
13
+
<methodsynopsis role="mysqli_stmt">
14
+
<modifier>public</modifier> <type>bool</type><methodname>mysqli_stmt::bind_param</methodname>
15
15
<methodparam><type>string</type><parameter>types</parameter></methodparam>
16
-
<methodparam><type>mixed</type><parameter role="reference">var1</parameter></methodparam>
17
-
<methodparam choice="opt"><type>mixed</type><parameter role="reference">...</parameter></methodparam>
16
+
<methodparam><type>mixed</type><parameter role="reference">var</parameter></methodparam>
17
+
<methodparam rep="repeat"><type>mixed</type><parameter role="reference">vars</parameter></methodparam>
18
18
</methodsynopsis>
19
19
<para>&style.procedural;</para>
20
20
<methodsynopsis>
21
21
<type>bool</type><methodname>mysqli_stmt_bind_param</methodname>
22
-
<methodparam><type>mysqli_stmt</type><parameter>stmt</parameter></methodparam>
22
+
<methodparam><type>mysqli_stmt</type><parameter>statement</parameter></methodparam>
23
23
<methodparam><type>string</type><parameter>types</parameter></methodparam>
24
-
<methodparam><type>mixed</type><parameter role="reference">var1</parameter></methodparam>
25
-
<methodparam choice="opt"><type>mixed</type><parameter role="reference">...</parameter></methodparam>
24
+
<methodparam><type>mixed</type><parameter role="reference">var</parameter></methodparam>
25
+
<methodparam rep="repeat"><type>mixed</type><parameter role="reference">vars</parameter></methodparam>
26
26
</methodsynopsis>
27
27
<para>
28
-
Bind variables for the parameter markers in the SQL statement that was
29
-
passed to <function>mysqli_prepare</function>.
28
+
Bind variables for the parameter markers in the SQL statement prepared by
29
+
<function>mysqli_prepare</function> or <function>mysqli_stmt_prepare</function>.
30
30
</para>
31
31
<note>
32
32
<para>
...
...
@@ -57,7 +57,7 @@
57
57
<para>
58
58
A string that contains one or more characters which specify the types
59
59
for the corresponding bind variables:
60
-
<table>
60
+
<table xml:id="mysqli-stmt.bind-param.parameters">
61
61
<title>Type specification chars</title>
62
62
<tgroup cols="2">
63
63
<thead>
...
...
@@ -69,15 +69,15 @@
69
69
<tbody>
70
70
<row>
71
71
<entry>i</entry>
72
-
<entry>corresponding variable has type integer</entry>
72
+
<entry>corresponding variable has type <type>int</type></entry>
73
73
</row>
74
74
<row>
75
75
<entry>d</entry>
76
-
<entry>corresponding variable has type double</entry>
76
+
<entry>corresponding variable has type <type>float</type></entry>
77
77
</row>
78
78
<row>
79
79
<entry>s</entry>
80
-
<entry>corresponding variable has type string</entry>
80
+
<entry>corresponding variable has type <type>string</type></entry>
81
81
</row>
82
82
<row>
83
83
<entry>b</entry>
...
...
@@ -90,7 +90,8 @@
90
90
</listitem>
91
91
</varlistentry>
92
92
<varlistentry>
93
-
<term><parameter>var1</parameter></term>
93
+
<term><parameter>var</parameter></term>
94
+
<term><parameter>vars</parameter></term>
94
95
<listitem>
95
96
<para>
96
97
The number of variables and length of string
...
...
@@ -109,20 +110,22 @@
109
110
</para>
110
111
</refsect1>
111
112

113
+
<refsect1 role="errors">
114
+
&reftitle.errors;
115
+
&mysqli.conditionalexception;
116
+
</refsect1>
117
+

112
118
<refsect1 role="examples">
113
119
&reftitle.examples;
114
120
<example>
115
-
<title>&style.oop;</title>
121
+
<title><methodname>mysqli_stmt::bind_param</methodname> example</title>
122
+
<para>&style.oop;</para>
116
123
<programlisting role="php">
117
124
<![CDATA[
118
125
<?php
119
-
$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'world');
120
126

121
-
/* check connection */
122
-
if (mysqli_connect_errno()) {
123
-
printf("Connect failed: %s\n", mysqli_connect_error());
124
-
exit();
125
-
}
127
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
128
+
$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'world');
126
129

127
130
$stmt = $mysqli->prepare("INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)");
128
131
$stmt->bind_param('sssd', $code, $language, $official, $percent);
...
...
@@ -132,36 +135,22 @@ $language = 'Bavarian';
132
135
$official = "F";
133
136
$percent = 11.2;
134
137

135
-
/* execute prepared statement */
136
138
$stmt->execute();
137
139

138
-
printf("%d Row inserted.\n", $stmt->affected_rows);
139
-

140
-
/* close statement and connection */
141
-
$stmt->close();
140
+
printf("%d row inserted.\n", $stmt->affected_rows);
142
141

143
142
/* Clean up table CountryLanguage */
144
143
$mysqli->query("DELETE FROM CountryLanguage WHERE Language='Bavarian'");
145
-
printf("%d Row deleted.\n", $mysqli->affected_rows);
146
-

147
-
/* close connection */
148
-
$mysqli->close();
149
-
?>
144
+
printf("%d row deleted.\n", $mysqli->affected_rows);
150
145
]]>
151
146
</programlisting>
152
-
</example>
153
-
<example>
154
-
<title>&style.procedural;</title>
147
+
<para>&style.procedural;</para>
155
148
<programlisting role="php">
156
149
<![CDATA[
157
150
<?php
158
-
$link = mysqli_connect('localhost', 'my_user', 'my_password', 'world');
159
151

160
-
/* check connection */
161
-
if (!$link) {
162
-
printf("Connect failed: %s\n", mysqli_connect_error());
163
-
exit();
164
-
}
152
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
153
+
$link = mysqli_connect('localhost', 'my_user', 'my_password', 'world');
165
154

166
155
$stmt = mysqli_prepare($link, "INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)");
167
156
mysqli_stmt_bind_param($stmt, 'sssd', $code, $language, $official, $percent);
...
...
@@ -171,28 +160,49 @@ $language = 'Bavarian';
171
160
$official = "F";
172
161
$percent = 11.2;
173
162

174
-
/* execute prepared statement */
175
163
mysqli_stmt_execute($stmt);
176
164

177
-
printf("%d Row inserted.\n", mysqli_stmt_affected_rows($stmt));
178
-

179
-
/* close statement and connection */
180
-
mysqli_stmt_close($stmt);
165
+
printf("%d row inserted.\n", mysqli_stmt_affected_rows($stmt));
181
166

182
167
/* Clean up table CountryLanguage */
183
168
mysqli_query($link, "DELETE FROM CountryLanguage WHERE Language='Bavarian'");
184
-
printf("%d Row deleted.\n", mysqli_affected_rows($link));
169
+
printf("%d row deleted.\n", mysqli_affected_rows($link));
170
+
]]>
171
+
</programlisting>
172
+
&examples.outputs;
173
+
<screen>
174
+
<![CDATA[
175
+
1 row inserted.
176
+
1 row deleted.
177
+
]]>
178
+
</screen>
179
+
</example>
180
+
<example>
181
+
<title>Using <literal>...</literal> to provide arguments</title>
182
+
<para>
183
+
The <literal>...</literal> operator can be used to provide variable-length
184
+
argument list, e.g. in a <literal>WHERE IN</literal> clause.
185
+
</para>
186
+
<programlisting role="php">
187
+
<![CDATA[
188
+
<?php
189
+

190
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
191
+
$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'world');
185
192

186
-
/* close connection */
187
-
mysqli_close($link);
188
-
?>
193
+
$stmt = $mysqli->prepare("SELECT Language FROM CountryLanguage WHERE CountryCode IN (?, ?)");
194
+
/* Using ... to provide arguments */
195
+
$stmt->bind_param('ss', ...['DEU', 'POL']);
196
+
$stmt->execute();
197
+
$stmt->store_result();
198
+

199
+
printf("%d rows found.\n", $stmt->num_rows());
189
200
]]>
190
201
</programlisting>
191
202
&examples.outputs;
192
203
<screen>
193
204
<![CDATA[
194
-
1 Row inserted.
195
-
1 Row deleted.
205
+
10 rows found.
196
206
]]>
197
207
</screen>
198
208
</example>
...
...
@@ -214,7 +224,6 @@ mysqli_close($link);
214
224
</refsect1>
215
225

216
226
</refentry>
217
-

218
227
<!-- Keep this comment at the end of the file
219
228
Local variables:
220
229
mode: sgml
221
230