reference/mysqli/mysqli_stmt/bind-result.xml
2e61d37d1d91ec32ecadf2a872e0a4109d02bc68
...
...
@@ -9,18 +9,18 @@
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_result</methodname>
15
-
<methodparam><type>mixed</type><parameter role="reference">var1</parameter></methodparam>
16
-
<methodparam choice="opt"><type>mixed</type><parameter role="reference">...</parameter></methodparam>
12
+
<para>&style.oop;</para>
13
+
<methodsynopsis role="mysqli_stmt">
14
+
<modifier>public</modifier> <type>bool</type><methodname>mysqli_stmt::bind_result</methodname>
15
+
<methodparam><type>mixed</type><parameter role="reference">var</parameter></methodparam>
16
+
<methodparam rep="repeat"><type>mixed</type><parameter role="reference">vars</parameter></methodparam>
17
17
</methodsynopsis>
18
-
<para>Procedural style:</para>
18
+
<para>&style.procedural;</para>
19
19
<methodsynopsis>
20
20
<type>bool</type><methodname>mysqli_stmt_bind_result</methodname>
21
-
<methodparam><type>mysqli_stmt</type><parameter>stmt</parameter></methodparam>
22
-
<methodparam><type>mixed</type><parameter role="reference">var1</parameter></methodparam>
23
-
<methodparam choice="opt"><type>mixed</type><parameter role="reference">...</parameter></methodparam>
21
+
<methodparam><type>mysqli_stmt</type><parameter>statement</parameter></methodparam>
22
+
<methodparam><type>mixed</type><parameter role="reference">var</parameter></methodparam>
23
+
<methodparam rep="repeat"><type>mixed</type><parameter role="reference">vars</parameter></methodparam>
24
24
</methodsynopsis>
25
25
<para>
26
26
Binds columns in the result set to variables.
...
...
@@ -28,22 +28,33 @@
28
28
<para>
29
29
When <function>mysqli_stmt_fetch</function> is called to fetch data, the
30
30
MySQL client/server protocol places the data for the bound columns into
31
-
the specified variables <parameter>var1, ...</parameter>.
31
+
the specified variables <parameter>var</parameter>/<parameter>vars</parameter>.
32
+
</para>
33
+
<para>
34
+
A column can be bound or rebound at any time, even after a result set has
35
+
been partially retrieved. The new binding takes effect the next time
36
+
<function>mysqli_stmt_fetch</function> is called.
32
37
</para>
33
38
<note>
34
39
<para>
35
-
Note that all columns must be bound after
40
+
All columns must be bound after
36
41
<function>mysqli_stmt_execute</function> and prior to calling
37
42
<function>mysqli_stmt_fetch</function>.
43
+
</para>
44
+
</note>
45
+
<note>
46
+
<para>
38
47
Depending on column types bound variables can silently change to the
39
48
corresponding PHP type.
40
49
</para>
50
+
</note>
51
+
<tip>
41
52
<para>
42
-
A column can be bound or rebound at any time, even after a result set has
43
-
been partially retrieved. The new binding takes effect the next time
44
-
<function>mysqli_stmt_fetch</function> is called.
53
+
This function is useful for simple results. To retrieve iterable result
54
+
set, or fetch each row as an array or object,
55
+
use <function>mysqli_stmt_get_result</function>.
45
56
</para>
46
-
</note>
57
+
</tip>
47
58
</refsect1>
48
59

49
60
<refsect1 role="parameters">
...
...
@@ -52,10 +63,18 @@
52
63
<variablelist>
53
64
&mysqli.stmt.description;
54
65
<varlistentry>
55
-
<term><parameter>var1</parameter></term>
66
+
<term><parameter>var</parameter></term>
67
+
<listitem>
68
+
<para>
69
+
The first variable to be bound.
70
+
</para>
71
+
</listitem>
72
+
</varlistentry>
73
+
<varlistentry>
74
+
<term><parameter>vars</parameter></term>
56
75
<listitem>
57
76
<para>
58
-
The variable to be bound.
77
+
Further variables to be bound.
59
78
</para>
60
79
</listitem>
61
80
</varlistentry>
...
...
@@ -73,76 +92,52 @@
73
92
<refsect1 role="examples">
74
93
&reftitle.examples;
75
94
<example>
76
-
<title>Object oriented style</title>
95
+
<title>&style.oop;</title>
77
96
<programlisting role="php">
78
97
<![CDATA[
79
98
<?php
80
-
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
81
99

82
-
if (mysqli_connect_errno()) {
83
-
printf("Connect failed: %s\n", mysqli_connect_error());
84
-
exit();
85
-
}
100
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
101
+
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
86
102

87
103
/* prepare statement */
88
-
if ($stmt = $mysqli->prepare("SELECT Code, Name FROM Country ORDER BY Name LIMIT 5")) {
89
-
$stmt->execute();
90
-

91
-
/* bind variables to prepared statement */
92
-
$stmt->bind_result($col1, $col2);
104
+
$stmt = $mysqli->prepare("SELECT Code, Name FROM Country ORDER BY Name LIMIT 5");
105
+
$stmt->execute();
93
106

94
-
/* fetch values */
95
-
while ($stmt->fetch()) {
96
-
printf("%s %s\n", $col1, $col2);
97
-
}
107
+
/* bind variables to prepared statement */
108
+
$stmt->bind_result($col1, $col2);
98
109

99
-
/* close statement */
100
-
$stmt->close();
110
+
/* fetch values */
111
+
while ($stmt->fetch()) {
112
+
printf("%s %s\n", $col1, $col2);
101
113
}
102
-
/* close connection */
103
-
$mysqli->close();
104
-

105
-
?>
106
114
]]>
107
-
</programlisting>
115
+
</programlisting>
108
116
</example>
109
117
<example>
110
-
<title>Procedural style</title>
118
+
<title>&style.procedural;</title>
111
119
<programlisting role="php">
112
120
<![CDATA[
113
121
<?php
114
-
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
115
122

116
-
/* check connection */
117
-
if (!$link) {
118
-
printf("Connect failed: %s\n", mysqli_connect_error());
119
-
exit();
120
-
}
123
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
124
+
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
121
125

122
126
/* prepare statement */
123
-
if ($stmt = mysqli_prepare($link, "SELECT Code, Name FROM Country ORDER BY Name LIMIT 5")) {
124
-
mysqli_stmt_execute($stmt);
127
+
$stmt = mysqli_prepare($link, "SELECT Code, Name FROM Country ORDER BY Name LIMIT 5");
128
+
mysqli_stmt_execute($stmt);
125
129

126
-
/* bind variables to prepared statement */
127
-
mysqli_stmt_bind_result($stmt, $col1, $col2);
130
+
/* bind variables to prepared statement */
131
+
mysqli_stmt_bind_result($stmt, $col1, $col2);
128
132

129
-
/* fetch values */
130
-
while (mysqli_stmt_fetch($stmt)) {
131
-
printf("%s %s\n", $col1, $col2);
132
-
}
133
-

134
-
/* close statement */
135
-
mysqli_stmt_close($stmt);
133
+
/* fetch values */
134
+
while (mysqli_stmt_fetch($stmt)) {
135
+
printf("%s %s\n", $col1, $col2);
136
136
}
137
-

138
-
/* close connection */
139
-
mysqli_close($link);
140
-
?>
141
137
]]>
142
138
</programlisting>
143
-
</example>
144
-
&example.outputs;
145
-
<screen>
139
+
&examples.outputs.similar;
140
+
<screen>
146
141
<![CDATA[
147
142
AFG Afghanistan
148
143
ALB Albania
...
...
@@ -150,27 +145,25 @@ DZA Algeria
150
145
ASM American Samoa
151
146
AND Andorra
152
147
]]>
153
-
</screen>
148
+
</screen>
149
+
</example>
154
150
</refsect1>
155
151

156
152
<refsect1 role="seealso">
157
153
&reftitle.seealso;
158
154
<para>
159
155
<simplelist>
156
+
<member><function>mysqli_stmt_get_result</function></member>
160
157
<member><function>mysqli_stmt_bind_param</function></member>
161
158
<member><function>mysqli_stmt_execute</function></member>
162
159
<member><function>mysqli_stmt_fetch</function></member>
163
160
<member><function>mysqli_prepare</function></member>
164
161
<member><function>mysqli_stmt_prepare</function></member>
165
-
<member><function>mysqli_stmt_init</function></member>
166
-
<member><function>mysqli_stmt_errno</function></member>
167
-
<member><function>mysqli_stmt_error</function></member>
168
162
</simplelist>
169
163
</para>
170
164
</refsect1>
171
165

172
166
</refentry>
173
-

174
167
<!-- Keep this comment at the end of the file
175
168
Local variables:
176
169
mode: sgml
177
170