reference/mysqli/mysqli_result/fetch-fields.xml
5152c78db935ea2463e20a01ae0e3f3573314d78
...
...
@@ -9,12 +9,12 @@
9
9

10
10
<refsect1 role="description">
11
11
&reftitle.description;
12
-
<para>Object oriented style (method):</para>
13
-
<methodsynopsis>
14
-
<type>array</type><methodname>mysqli_result::fetch_fields</methodname>
12
+
<para>&style.oop;</para>
13
+
<methodsynopsis role="mysqli_result">
14
+
<modifier>public</modifier> <type>array</type><methodname>mysqli_result::fetch_fields</methodname>
15
15
<void/>
16
16
</methodsynopsis>
17
-
<para>Procedural Style:</para>
17
+
<para>&style.procedural;</para>
18
18
<methodsynopsis>
19
19
<type>array</type><methodname>mysqli_fetch_fields</methodname>
20
20
<methodparam><type>mysqli_result</type><parameter>result</parameter></methodparam>
...
...
@@ -40,13 +40,12 @@
40
40
<refsect1 role="returnvalues">
41
41
&reftitle.returnvalues;
42
42
<para>
43
-
Returns an array of objects which contains field definition information or
44
-
&false; if no field information is available.
43
+
Returns an array of objects containing field definition information.
45
44
</para>
46
-
<para>
45
+

47
46
<table>
48
47
<title>Object properties</title>
49
-
<tgroup cols='2'>
48
+
<tgroup cols="2">
50
49
<thead>
51
50
<row>
52
51
<entry>Property</entry>
...
...
@@ -72,15 +71,30 @@
72
71
</row>
73
72
<row>
74
73
<entry>def</entry>
75
-
<entry>The default value for this field, represented as a string</entry>
74
+
<entry>Unused. Always an empty string</entry>
75
+
</row>
76
+
<row>
77
+
<entry>db</entry>
78
+
<entry>The name of the database</entry>
79
+
</row>
80
+
<row>
81
+
<entry>catalog</entry>
82
+
<entry>Unused. Always <literal>"def"</literal></entry>
76
83
</row>
77
84
<row>
78
85
<entry>max_length</entry>
79
-
<entry>The maximum width of the field for the result set.</entry>
86
+
<entry>The maximum width of the field for the result set. As of PHP 8.1, this value is always <literal>0</literal>.</entry>
80
87
</row>
81
88
<row>
82
89
<entry>length</entry>
83
-
<entry>The width of the field, as specified in the table definition.</entry>
90
+
<entry>
91
+
The width of the field in bytes. For string columns,
92
+
the length value varies on the connection character set. For example,
93
+
if the character set is <literal>latin1</literal>, a single-byte character set,
94
+
the length value for a <literal>SELECT 'abc'</literal> query is 3.
95
+
If the character set is <literal>utf8mb4</literal>, a multibyte character
96
+
set in which characters take up to 4 bytes, the length value is 12.
97
+
</entry>
84
98
</row>
85
99
<row>
86
100
<entry>charsetnr</entry>
...
...
@@ -96,58 +110,67 @@
96
110
</row>
97
111
<row>
98
112
<entry>decimals</entry>
99
-
<entry>The number of decimals used (for integer fields)</entry>
113
+
<entry>The number of decimals for numeric fields, and the fractional seconds precision for temporal fields.</entry>
100
114
</row>
101
115
</tbody>
102
116
</tgroup>
103
117
</table>
104
-
</para>
105
118
</refsect1>
106
119

107
120
<refsect1 role="examples">
108
121
&reftitle.examples;
109
122
<example>
110
-
<title>Object oriented style</title>
123
+
<title>&style.oop;</title>
111
124
<programlisting role="php">
112
125
<![CDATA[
113
126
<?php
114
-
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
127
+
$mysqli = new mysqli("127.0.0.1", "root", "foofoo", "sakila");
115
128

116
129
/* check connection */
117
-
if (mysqli_connect_errno()) {
118
-
printf("Connect failed: %s\n", mysqli_connect_error());
130
+
if ($mysqli->connect_errno) {
131
+
printf("Connect failed: %s\n", $mysqli->connect_error);
119
132
exit();
120
133
}
121
134

122
-
$query = "SELECT Name, SurfaceArea from Country ORDER BY Code LIMIT 5";
135
+
foreach (array('latin1', 'utf8') as $charset) {
136
+

137
+
// Set character set, to show its impact on some values (e.g., length in bytes)
138
+
$mysqli->set_charset($charset);
139
+

140
+
$query = "SELECT actor_id, last_name from actor ORDER BY actor_id";
123
141

124
-
if ($result = $mysqli->query($query)) {
142
+
echo "======================\n";
143
+
echo "Character Set: $charset\n";
144
+
echo "======================\n";
125
145
126
-
/* Get field information for all columns */
127
-
$finfo = $result->fetch_fields();
146
+
if ($result = $mysqli->query($query)) {
128
147

129
-
foreach ($finfo as $val) {
130
-
printf("Name: %s\n", $val->name);
131
-
printf("Table: %s\n", $val->table);
132
-
printf("max. Len: %d\n", $val->max_length);
133
-
printf("Flags: %d\n", $val->flags);
134
-
printf("Type: %d\n\n", $val->type);
148
+
/* Get field information for all columns */
149
+
$finfo = $result->fetch_fields();
150
+

151
+
foreach ($finfo as $val) {
152
+
printf("Name: %s\n", $val->name);
153
+
printf("Table: %s\n", $val->table);
154
+
printf("Max. Len: %d\n", $val->max_length);
155
+
printf("Length: %d\n", $val->length);
156
+
printf("charsetnr: %d\n", $val->charsetnr);
157
+
printf("Flags: %d\n", $val->flags);
158
+
printf("Type: %d\n\n", $val->type);
159
+
}
160
+
$result->free();
135
161
}
136
-
$result->close();
137
162
}
138
-

139
-
/* close connection */
140
163
$mysqli->close();
141
164
?>
142
165
]]>
143
-
</programlisting>
166
+
</programlisting>
144
167
</example>
145
168
<example>
146
-
<title>Procedural style</title>
169
+
<title>&style.procedural;</title>
147
170
<programlisting role="php">
148
171
<![CDATA[
149
172
<?php
150
-
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
173
+
$link = mysqli_connect("127.0.0.1", "my_user", "my_password", "sakila");
151
174

152
175
/* check connection */
153
176
if (mysqli_connect_errno()) {
...
...
@@ -155,46 +178,81 @@ if (mysqli_connect_errno()) {
155
178
exit();
156
179
}
157
180

158
-
$query = "SELECT Name, SurfaceArea from Country ORDER BY Code LIMIT 5";
181
+
foreach (array('latin1', 'utf8') as $charset) {
182
+

183
+
// Set character set, to show its impact on some values (e.g., length in bytes)
184
+
mysqli_set_charset($link, $charset);
185
+

186
+
$query = "SELECT actor_id, last_name from actor ORDER BY actor_id";
187
+

188
+
echo "======================\n";
189
+
echo "Character Set: $charset\n";
190
+
echo "======================\n";
159
191

160
-
if ($result = mysqli_query($link, $query)) {
192
+
if ($result = mysqli_query($link, $query)) {
161
193

162
-
/* Get field information for all columns */
163
-
$finfo = mysqli_fetch_fields($result);
194
+
/* Get field information for all columns */
195
+
$finfo = mysqli_fetch_fields($result);
164
196

165
-
foreach ($finfo as $val) {
166
-
printf("Name: %s\n", $val->name);
167
-
printf("Table: %s\n", $val->table);
168
-
printf("max. Len: %d\n", $val->max_length);
169
-
printf("Flags: %d\n", $val->flags);
170
-
printf("Type: %d\n\n", $val->type);
197
+
foreach ($finfo as $val) {
198
+
printf("Name: %s\n", $val->name);
199
+
printf("Table: %s\n", $val->table);
200
+
printf("Max. Len: %d\n", $val->max_length);
201
+
printf("Length: %d\n", $val->length);
202
+
printf("charsetnr: %d\n", $val->charsetnr);
203
+
printf("Flags: %d\n", $val->flags);
204
+
printf("Type: %d\n\n", $val->type);
205
+
}
206
+
mysqli_free_result($result);
171
207
}
172
-
mysqli_free_result($result);
173
208
}
174
209

175
-
/* close connection */
176
210
mysqli_close($link);
177
211
?>
178
212
]]>
179
213
</programlisting>
180
-
</example>
181
-
&example.outputs;
182
-
<screen>
214
+
&examples.outputs;
215
+
<screen>
183
216
<![CDATA[
184
-
Name: Name
185
-
Table: Country
186
-
max. Len: 11
187
-
Flags: 1
188
-
Type: 254
189
-

190
-
Name: SurfaceArea
191
-
Table: Country
192
-
max. Len: 10
193
-
Flags: 32769
194
-
Type: 4
217
+
======================
218
+
Character Set: latin1
219
+
======================
220
+
Name: actor_id
221
+
Table: actor
222
+
Max. Len: 3
223
+
Length: 5
224
+
charsetnr: 63
225
+
Flags: 49699
226
+
Type: 2
227
+

228
+
Name: last_name
229
+
Table: actor
230
+
Max. Len: 12
231
+
Length: 45
232
+
charsetnr: 8
233
+
Flags: 20489
234
+
Type: 253
235
+

236
+
======================
237
+
Character Set: utf8
238
+
======================
239
+
Name: actor_id
240
+
Table: actor
241
+
Max. Len: 3
242
+
Length: 5
243
+
charsetnr: 63
244
+
Flags: 49699
245
+
Type: 2
195
246

247
+
Name: last_name
248
+
Table: actor
249
+
Max. Len: 12
250
+
Length: 135
251
+
charsetnr: 33
252
+
Flags: 20489
196
253
]]>
197
-
</screen>
254
+
</screen>
255
+
</example>
198
256
</refsect1>
199
257

200
258
<refsect1 role="seealso">
...
...
@@ -209,7 +267,6 @@ Type: 4
209
267
</refsect1>
210
268

211
269
</refentry>
212
-

213
270
<!-- Keep this comment at the end of the file
214
271
Local variables:
215
272
mode: sgml
216
273