reference/mysqli/mysqli_result/fetch-object.xml
c5ccd084c8f830801a939bf1829ddddcaf019730
...
...
@@ -4,28 +4,37 @@
4
4
<refnamediv>
5
5
<refname>mysqli_result::fetch_object</refname>
6
6
<refname>mysqli_fetch_object</refname>
7
-
<refpurpose>Returns the current row of a result set as an object</refpurpose>
7
+
<refpurpose>Fetch the next row of a result set as an object</refpurpose>
8
8
</refnamediv>
9
9

10
10
<refsect1 role="description">
11
11
&reftitle.description;
12
12
<para>&style.oop;</para>
13
-
<methodsynopsis role="oop">
13
+
<methodsynopsis role="mysqli_result">
14
14
<modifier>public</modifier> <type class="union"><type>object</type><type>null</type><type>false</type></type><methodname>mysqli_result::fetch_object</methodname>
15
15
<methodparam choice="opt"><type>string</type><parameter>class</parameter><initializer>"stdClass"</initializer></methodparam>
16
16
<methodparam choice="opt"><type>array</type><parameter>constructor_args</parameter><initializer>[]</initializer></methodparam>
17
17
</methodsynopsis>
18
18
<para>&style.procedural;</para>
19
-
<methodsynopsis role="procedural">
19
+
<methodsynopsis>
20
20
<type class="union"><type>object</type><type>null</type><type>false</type></type><methodname>mysqli_fetch_object</methodname>
21
21
<methodparam><type>mysqli_result</type><parameter>result</parameter></methodparam>
22
22
<methodparam choice="opt"><type>string</type><parameter>class</parameter><initializer>"stdClass"</initializer></methodparam>
23
23
<methodparam choice="opt"><type>array</type><parameter>constructor_args</parameter><initializer>[]</initializer></methodparam>
24
24
</methodsynopsis>
25
25
<para>
26
-
Returns the current row
27
-
result set as an object where the attributes of the object represent the
28
-
names of the fields found within the result set.
26
+
Fetches one row of data from the result set and returns it as an object,
27
+
where each property represents the name of the result set's column.
28
+
Each subsequent call to this function will return the next row within the
29
+
result set, or &null; if there are no more rows.
30
+
</para>
31
+
<para>
32
+
If two or more columns of the result have the same name, the last
33
+
column will take precedence and overwrite any previous data. To
34
+
access multiple columns with the same name,
35
+
<function>mysqli_fetch_row</function> may be used to fetch the numerically
36
+
indexed array, or aliases may be used in the SQL query select list to give
37
+
columns different names.
29
38
</para>
30
39
<note xmlns="http://docbook.org/ns/docbook">
31
40
<simpara>
...
...
@@ -67,8 +76,17 @@
67
76
<refsect1 role="returnvalues">
68
77
&reftitle.returnvalues;
69
78
<para>
70
-
Returns an object that corresponds to the fetched
71
-
row or &null; if there are no more rows in result set.
79
+
Returns an object representing the fetched row, where each property
80
+
represents the name of the result set's column, &null; if there
81
+
are no more rows in the result set, &return.falseforfailure;.
82
+
</para>
83
+
</refsect1>
84
+

85
+
<refsect1 role="errors">
86
+
&reftitle.errors;
87
+
<para>
88
+
A <classname>ValueError</classname> is thrown when
89
+
the <parameter>constructor_args</parameter> is non-empty with the class not having constructor.
72
90
</para>
73
91
</refsect1>
74
92

...
...
@@ -84,6 +102,14 @@
84
102
</thead>
85
103
<tbody>
86
104
<row>
105
+
<entry>8.3.0</entry>
106
+
<entry>
107
+
Now throws a <classname>ValueError</classname> exception when
108
+
the <parameter>constructor_args</parameter> is non-empty with the class not having constructor;
109
+
previously an <classname>Exception</classname> was thrown.
110
+
</entry>
111
+
</row>
112
+
<row>
87
113
<entry>8.0.0</entry>
88
114
<entry>
89
115
<parameter>constructor_args</parameter> now accepts <literal>[]</literal> for constructors with 0 parameters;
...
...
@@ -111,7 +137,6 @@ $query = "SELECT Name, CountryCode FROM City ORDER BY ID DESC";
111
137

112
138
$result = $mysqli->query($query);
113
139

114
-
/* fetch object array */
115
140
while ($obj = $result->fetch_object()) {
116
141
printf("%s (%s)\n", $obj->Name, $obj->CountryCode);
117
142
}
...
...
@@ -129,7 +154,6 @@ $query = "SELECT Name, CountryCode FROM City ORDER BY ID DESC";
129
154

130
155
$result = mysqli_query($link, $query);
131
156

132
-
/* fetch associative array */
133
157
while ($obj = mysqli_fetch_object($result)) {
134
158
printf("%s (%s)\n", $obj->Name, $obj->CountryCode);
135
159
}
...
...
@@ -154,6 +178,7 @@ Santa Clara (USA)
154
178
<simplelist>
155
179
<member><function>mysqli_fetch_array</function></member>
156
180
<member><function>mysqli_fetch_assoc</function></member>
181
+
<member><function>mysqli_fetch_column</function></member>
157
182
<member><function>mysqli_fetch_row</function></member>
158
183
<member><function>mysqli_query</function></member>
159
184
<member><function>mysqli_data_seek</function></member>
160
185