reference/mysqli/mysqli_stmt/bind-result.xml
2e61d37d1d91ec32ecadf2a872e0a4109d02bc68
...
...
@@ -10,7 +10,7 @@
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::bind_result</methodname>
15
15
<methodparam><type>mixed</type><parameter role="reference">var</parameter></methodparam>
16
16
<methodparam rep="repeat"><type>mixed</type><parameter role="reference">vars</parameter></methodparam>
...
...
@@ -18,7 +18,7 @@
18
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>
21
+
<methodparam><type>mysqli_stmt</type><parameter>statement</parameter></methodparam>
22
22
<methodparam><type>mixed</type><parameter role="reference">var</parameter></methodparam>
23
23
<methodparam rep="repeat"><type>mixed</type><parameter role="reference">vars</parameter></methodparam>
24
24
</methodsynopsis>
...
...
@@ -30,20 +30,31 @@
30
30
MySQL client/server protocol places the data for the bound columns into
31
31
the specified variables <parameter>var</parameter>/<parameter>vars</parameter>.
32
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.
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">
...
...
@@ -85,32 +96,21 @@
85
96
<programlisting role="php">
86
97
<![CDATA[
87
98
<?php
88
-
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
89
99

90
-
if (mysqli_connect_errno()) {
91
-
printf("Connect failed: %s\n", mysqli_connect_error());
92
-
exit();
93
-
}
100
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
101
+
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
94
102

95
103
/* prepare statement */
96
-
if ($stmt = $mysqli->prepare("SELECT Code, Name FROM Country ORDER BY Name LIMIT 5")) {
97
-
$stmt->execute();
98
-

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

102
-
/* fetch values */
103
-
while ($stmt->fetch()) {
104
-
printf("%s %s\n", $col1, $col2);
105
-
}
107
+
/* bind variables to prepared statement */
108
+
$stmt->bind_result($col1, $col2);
106
109

107
-
/* close statement */
108
-
$stmt->close();
110
+
/* fetch values */
111
+
while ($stmt->fetch()) {
112
+
printf("%s %s\n", $col1, $col2);
109
113
}
110
-
/* close connection */
111
-
$mysqli->close();
112
-

113
-
?>
114
114
]]>
115
115
</programlisting>
116
116
</example>
...
...
@@ -119,36 +119,24 @@ $mysqli->close();
119
119
<programlisting role="php">
120
120
<![CDATA[
121
121
<?php
122
-
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
123
122

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

130
126
/* prepare statement */
131
-
if ($stmt = mysqli_prepare($link, "SELECT Code, Name FROM Country ORDER BY Name LIMIT 5")) {
132
-
mysqli_stmt_execute($stmt);
133
-

134
-
/* bind variables to prepared statement */
135
-
mysqli_stmt_bind_result($stmt, $col1, $col2);
127
+
$stmt = mysqli_prepare($link, "SELECT Code, Name FROM Country ORDER BY Name LIMIT 5");
128
+
mysqli_stmt_execute($stmt);
136
129

137
-
/* fetch values */
138
-
while (mysqli_stmt_fetch($stmt)) {
139
-
printf("%s %s\n", $col1, $col2);
140
-
}
130
+
/* bind variables to prepared statement */
131
+
mysqli_stmt_bind_result($stmt, $col1, $col2);
141
132

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

146
-
/* close connection */
147
-
mysqli_close($link);
148
-
?>
149
137
]]>
150
138
</programlisting>
151
-
&examples.outputs;
139
+
&examples.outputs.similar;
152
140
<screen>
153
141
<![CDATA[
154
142
AFG Afghanistan
...
...
@@ -171,15 +159,11 @@ AND Andorra
171
159
<member><function>mysqli_stmt_fetch</function></member>
172
160
<member><function>mysqli_prepare</function></member>
173
161
<member><function>mysqli_stmt_prepare</function></member>
174
-
<member><function>mysqli_stmt_init</function></member>
175
-
<member><function>mysqli_stmt_errno</function></member>
176
-
<member><function>mysqli_stmt_error</function></member>
177
162
</simplelist>
178
163
</para>
179
164
</refsect1>
180
165

181
166
</refentry>
182
-

183
167
<!-- Keep this comment at the end of the file
184
168
Local variables:
185
169
mode: sgml
186
170