You elect to use object notation, but for some reason then decide to access the results as an array, which on the face of it makes little sense.
You then take the array of results and assign them to yet another array using $Rows[] array notation.
So when you use gettype well, that is telling you that you have an array of arrays - which is what you just did above.
The db returns an array of results, which contains arrays, then you assign it to another array.
I don't know why gettype $row returns null.
If you like the object notation (->) and you have no other cause to use arrays then you could access your result set as objects too as seen in this code from the manual:
PHP Code:
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 50,5";
if ($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();
}
/* close connection */
$mysqli->close();
?>
If you are doing lots of array comparisons with your results then fetching arrays is a good thing, but otherwise I learned early on (after frequently visiting nested array hell myself
) that using the object notation wherever possible is a) easier to read (for me) b) easier to use in double quotes (you dont need to concat strings and c) really gets you into the mode of thinking about OOP.
PHP Code:
// this is less error prone, less typing, easier to scan
echo "I live in $obj->Country now.";
//vs
// than this
echo "I live in " . $row['Country'] . " now";
Bookmarks