diff --git a/reference/mysqli/mysqli_result/fetch-array.xml b/reference/mysqli/mysqli_result/fetch-array.xml
index 993a796248..d790051e4a 100644
--- a/reference/mysqli/mysqli_result/fetch-array.xml
+++ b/reference/mysqli/mysqli_result/fetch-array.xml
@@ -22,15 +22,12 @@
Returns an array that corresponds to the fetched row or &null; if there
- are no more rows for the resultset represented by the
- result parameter.
+ are no more rows for the result set.
- mysqli_fetch_array is an extended version of the
- mysqli_fetch_row function. In addition to storing the
- data in the numeric indices of the result array, the
- mysqli_fetch_array function can also store the data
- in associative indices, using the field names of the result set as keys.
+ In addition to storing the data in the numeric indices of the result array,
+ this function can also store the data in associative indices
+ by using the field names of the result set as keys.
&database.field-case;
&database.fetch-null;
@@ -73,87 +70,64 @@
&reftitle.returnvalues;
- Returns an array of strings that corresponds to the fetched row or &null; if there
- are no more rows in resultset.
+ Returns an array of values that corresponds to the fetched row or &null; if there
+ are no more rows in result set.
&reftitle.examples;
- &style.oop;
+ mysqli_result::fetch_array example
+ &style.oop;
connect_errno) {
- printf("Connect failed: %s\n", $mysqli->connect_error);
- exit();
-}
-
-$query = "SELECT Name, CountryCode FROM City ORDER by ID LIMIT 3";
+$query = "SELECT Name, CountryCode FROM City ORDER BY ID LIMIT 3";
$result = $mysqli->query($query);
/* numeric array */
$row = $result->fetch_array(MYSQLI_NUM);
-printf ("%s (%s)\n", $row[0], $row[1]);
+printf("%s (%s)\n", $row[0], $row[1]);
/* associative array */
$row = $result->fetch_array(MYSQLI_ASSOC);
-printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);
+printf("%s (%s)\n", $row["Name"], $row["CountryCode"]);
/* associative and numeric array */
$row = $result->fetch_array(MYSQLI_BOTH);
-printf ("%s (%s)\n", $row[0], $row["CountryCode"]);
-
-/* free result set */
-$result->free();
-
-/* close connection */
-$mysqli->close();
-?>
+printf("%s (%s)\n", $row[0], $row["CountryCode"]);
]]>
-
-
- &style.procedural;
+ &style.procedural;
+printf("%s (%s)\n", $row[0], $row["CountryCode"]);
]]>
- &examples.outputs;
+ &examples.outputs.similar;
&reftitle.returnvalues;
- Returns an associative array of strings representing the fetched row in the result
+ Returns an associative array of values representing the fetched row in the result
set, where each key in the array represents the name of one of the result
- set's columns or &null; if there are no more rows in resultset.
+ set's columns or &null; if there are no more rows in result set.
If two or more columns of the result have the same field names, the last
@@ -54,69 +54,44 @@
&reftitle.examples;
- &style.oop;
+ mysqli_result::fetch_assoc example
+ &style.oop;
connect_errno) {
- printf("Connect failed: %s\n", $mysqli->connect_error);
- exit();
+$query = "SELECT Name, CountryCode FROM City ORDER BY ID DESC";
+
+$result = $mysqli->query($query);
+
+/* fetch associative array */
+while ($row = $result->fetch_assoc()) {
+ printf("%s (%s)\n", $row["Name"], $row["CountryCode"]);
}
-
-$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 50,5";
-
-if ($result = $mysqli->query($query)) {
-
- /* fetch associative array */
- while ($row = $result->fetch_assoc()) {
- printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);
- }
-
- /* free result set */
- $result->free();
-}
-
-/* close connection */
-$mysqli->close();
-?>
]]>
-
-
- &style.procedural;
+ &style.procedural;
]]>
- &examples.outputs;
+ &examples.outputs.similar;
- A mysqli_result example comparing iterator usage
+ Comparison of mysqli_result iterator and mysqli_result::fetch_assoc usage
+
+ mysqli_result can be iterated using &foreach;.
+ The result set will always be iterated from the first row, regardless of the current position.
+
query('SELECT user,host FROM mysql.user') as $row ) {
- printf("'%s'@'%s'\n", $row['user'], $row['host']);
+mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
+$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
+
+$query = 'SELECT Name, CountryCode FROM City ORDER BY ID DESC';
+
+// Using iterators
+$result = $mysqli->query($query);
+foreach ($result as $row) {
+ printf("%s (%s)\n", $row["Name"], $row["CountryCode"]);
}
echo "\n==================\n";
// Not using iterators
-$result = $c->query('SELECT user,host FROM mysql.user');
+$result = $mysqli->query($query);
while ($row = $result->fetch_assoc()) {
- printf("'%s'@'%s'\n", $row['user'], $row['host']);
+ printf("%s (%s)\n", $row["Name"], $row["CountryCode"]);
}
-
-?>
]]>
&example.outputs.similar;
diff --git a/reference/mysqli/mysqli_result/fetch-object.xml b/reference/mysqli/mysqli_result/fetch-object.xml
index 8bae4d918a..fe2a4139a7 100644
--- a/reference/mysqli/mysqli_result/fetch-object.xml
+++ b/reference/mysqli/mysqli_result/fetch-object.xml
@@ -23,14 +23,18 @@
arrayparams
- The mysqli_fetch_object will return the current row
+ Returns the current row
result set as an object where the attributes of the object represent the
names of the fields found within the result set.
-
- Note that mysqli_fetch_object sets the properties
- of the object before calling the object constructor.
-
+
+
+ This function sets the properties
+ of the object before calling the object constructor.
+
+
+ &database.field-case;
+ &database.fetch-null;
@@ -63,79 +67,52 @@
&reftitle.returnvalues;
- Returns an object with string properties that corresponds to the fetched
- row or &null; if there are no more rows in resultset.
+ Returns an object that corresponds to the fetched
+ row or &null; if there are no more rows in result set.
- &database.field-case;
- &database.fetch-null;
&reftitle.examples;
- &style.oop;
+ mysqli_result::fetch_object example
+ &style.oop;
query($query)) {
+$result = $mysqli->query($query);
- /* fetch object array */
- while ($obj = $result->fetch_object()) {
- printf ("%s (%s)\n", $obj->Name, $obj->CountryCode);
- }
-
- /* free result set */
- $result->close();
+/* fetch object array */
+while ($obj = $result->fetch_object()) {
+ printf("%s (%s)\n", $obj->Name, $obj->CountryCode);
}
-
-/* close connection */
-$mysqli->close();
-?>
]]>
-
-
- &style.procedural;
+ &style.procedural;
Name, $obj->CountryCode);
}
-
-$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 50,5";
-
-if ($result = mysqli_query($link, $query)) {
-
- /* fetch associative array */
- while ($obj = mysqli_fetch_object($result)) {
- printf ("%s (%s)\n", $obj->Name, $obj->CountryCode);
- }
-
- /* free result set */
- mysqli_free_result($result);
-}
-
-/* close connection */
-mysqli_close($link);
-?>
]]>
- &examples.outputs;
+ &examples.outputs.similar;
+ &database.fetch-null;
@@ -39,78 +40,52 @@
&reftitle.returnvalues;
- mysqli_fetch_row returns an array of strings that corresponds to the fetched row
+ mysqli_fetch_row returns an array of values that corresponds to the fetched row
or &null; if there are no more rows in result set.
- &database.fetch-null;
&reftitle.examples;
- &style.oop;
+ mysqli_result::fetch_row example
+ &style.oop;
query($query);
+
+/* fetch object array */
+while ($row = $result->fetch_row()) {
+ printf("%s (%s)\n", $row[0], $row[1]);
}
-
-$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 50,5";
-
-if ($result = $mysqli->query($query)) {
-
- /* fetch object array */
- while ($row = $result->fetch_row()) {
- printf ("%s (%s)\n", $row[0], $row[1]);
- }
-
- /* free result set */
- $result->close();
-}
-
-/* close connection */
-$mysqli->close();
-?>
]]>
-
-
- &style.procedural;
+ &style.procedural;
]]>
- &examples.outputs;
+ &examples.outputs.similar;