reference/mysqli/mysqli_stmt/bind-param.xml
63b99082ef83eade08151f8cb528246fded81db9
...
...
@@ -1,4 +1,4 @@
1
-
<?xml version="1.0" encoding="iso-8859-1"?>
1
+
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
3
<refentry xml:id="mysqli-stmt.bind-param" xmlns="http://docbook.org/ns/docbook">
4
4
<refnamediv>
...
...
@@ -9,24 +9,24 @@
9
9

10
10
<refsect1 role="description">
11
11
&reftitle.description;
12
-
<para>Object oriented style (method):</para>
13
-
<methodsynopsis>
14
-
<type>bool</type><methodname>mysqli_stmt::bind_param</methodname>
12
+
<para>&style.oop;</para>
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
-
<para>Procedural style:</para>
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>
...
...
@@ -36,6 +36,14 @@
36
36
<function>mysqli_stmt_send_long_data</function> to send the data in packets.
37
37
</para>
38
38
</note>
39
+
<note>
40
+
<para>
41
+
Care must be taken when using <function>mysqli_stmt_bind_param</function> in conjunction
42
+
with <function>call_user_func_array</function>. Note that <function>mysqli_stmt_bind_param</function>
43
+
requires parameters to be passed by reference, whereas <function>call_user_func_array</function>
44
+
can accept as a parameter a list of variables that can represent references or values.
45
+
</para>
46
+
</note>
39
47
</refsect1>
40
48

41
49
<refsect1 role="parameters">
...
...
@@ -49,9 +57,9 @@
49
57
<para>
50
58
A string that contains one or more characters which specify the types
51
59
for the corresponding bind variables:
52
-
<table>
60
+
<table xml:id="mysqli-stmt.bind-param.parameters">
53
61
<title>Type specification chars</title>
54
-
<tgroup cols='2'>
62
+
<tgroup cols="2">
55
63
<thead>
56
64
<row>
57
65
<entry>Character</entry>
...
...
@@ -61,15 +69,15 @@
61
69
<tbody>
62
70
<row>
63
71
<entry>i</entry>
64
-
<entry>corresponding variable has type integer</entry>
72
+
<entry>corresponding variable has type <type>int</type></entry>
65
73
</row>
66
74
<row>
67
75
<entry>d</entry>
68
-
<entry>corresponding variable has type double</entry>
76
+
<entry>corresponding variable has type <type>float</type></entry>
69
77
</row>
70
78
<row>
71
79
<entry>s</entry>
72
-
<entry>corresponding variable has type string</entry>
80
+
<entry>corresponding variable has type <type>string</type></entry>
73
81
</row>
74
82
<row>
75
83
<entry>b</entry>
...
...
@@ -82,7 +90,8 @@
82
90
</listitem>
83
91
</varlistentry>
84
92
<varlistentry>
85
-
<term><parameter>var1</parameter></term>
93
+
<term><parameter>var</parameter></term>
94
+
<term><parameter>vars</parameter></term>
86
95
<listitem>
87
96
<para>
88
97
The number of variables and length of string
...
...
@@ -101,20 +110,22 @@
101
110
</para>
102
111
</refsect1>
103
112

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

104
118
<refsect1 role="examples">
105
119
&reftitle.examples;
106
120
<example>
107
-
<title>Object oriented style</title>
121
+
<title><methodname>mysqli_stmt::bind_param</methodname> example</title>
122
+
<para>&style.oop;</para>
108
123
<programlisting role="php">
109
124
<![CDATA[
110
125
<?php
111
-
$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'world');
112
126

113
-
/* check connection */
114
-
if (mysqli_connect_errno()) {
115
-
printf("Connect failed: %s\n", mysqli_connect_error());
116
-
exit();
117
-
}
127
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
128
+
$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'world');
118
129

119
130
$stmt = $mysqli->prepare("INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)");
120
131
$stmt->bind_param('sssd', $code, $language, $official, $percent);
...
...
@@ -124,36 +135,22 @@ $language = 'Bavarian';
124
135
$official = "F";
125
136
$percent = 11.2;
126
137

127
-
/* execute prepared statement */
128
138
$stmt->execute();
129
139

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

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

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

139
-
/* close connection */
140
-
$mysqli->close();
141
-
?>
144
+
printf("%d row deleted.\n", $mysqli->affected_rows);
142
145
]]>
143
-
</programlisting>
144
-
</example>
145
-
<example>
146
-
<title>Procedural style</title>
146
+
</programlisting>
147
+
<para>&style.procedural;</para>
147
148
<programlisting role="php">
148
149
<![CDATA[
149
150
<?php
150
-
$link = mysqli_connect('localhost', 'my_user', 'my_password', 'world');
151
151

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

158
155
$stmt = mysqli_prepare($link, "INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)");
159
156
mysqli_stmt_bind_param($stmt, 'sssd', $code, $language, $official, $percent);
...
...
@@ -163,31 +160,52 @@ $language = 'Bavarian';
163
160
$official = "F";
164
161
$percent = 11.2;
165
162

166
-
/* execute prepared statement */
167
163
mysqli_stmt_execute($stmt);
168
164

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

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

174
167
/* Clean up table CountryLanguage */
175
168
mysqli_query($link, "DELETE FROM CountryLanguage WHERE Language='Bavarian'");
176
-
printf("%d Row deleted.\n", mysqli_affected_rows($link));
177
-

178
-
/* close connection */
179
-
mysqli_close($link);
180
-
?>
169
+
printf("%d row deleted.\n", mysqli_affected_rows($link));
181
170
]]>
182
171
</programlisting>
172
+
&examples.outputs;
173
+
<screen>
174
+
<![CDATA[
175
+
1 row inserted.
176
+
1 row deleted.
177
+
]]>
178
+
</screen>
183
179
</example>
184
-
&example.outputs;
185
-
<screen>
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');
192
+

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());
200
+
]]>
201
+
</programlisting>
202
+
&examples.outputs;
203
+
<screen>
186
204
<![CDATA[
187
-
1 Row inserted.
188
-
1 Row deleted.
205
+
10 rows found.
189
206
]]>
190
-
</screen>
207
+
</screen>
208
+
</example>
191
209
</refsect1>
192
210

193
211
<refsect1 role="seealso">
...
...
@@ -206,7 +224,6 @@ mysqli_close($link);
206
224
</refsect1>
207
225

208
226
</refentry>
209
-

210
227
<!-- Keep this comment at the end of the file
211
228
Local variables:
212
229
mode: sgml
213
230