Why is fetch_assoc() not returning a value?
<p>For the life of me I can't figure out why fetch_assoc() is returning false here:</p>

<pre><code>$username = $_POST['username'];
print("Username is " . $username . "&lt;br&gt;");

//Create query
$query = ("SELECT * FROM users WHERE username = '" . $username . "'");
print($query . "&lt;br&gt;");

//Run query
if (!$result = $db2 -&gt; query($query)) {
    print("Query failed!");
}

if (!$user = new LG_User($result))
    print("Failed to create user!&lt;br&gt;");

while($row = $result -&gt; fetch_assoc()) {
    $rows[] = $row;
}
var_dump($rows);
print("User is " . $user -&gt; first_name . "&lt;br&gt;");
</code></pre>

<p>The query is successful and the new user object is created, because the last line of code is printing $user->first_name correctly. I'm using the very same block of code to populate the $rows array on another page and it is working. What am I doing wrong here? If I try to use </p>

<p><code>while($row = mysqli_fetch_assoc($result)) {
    $rows[] = $row;
}</code> </p>

<p>instead of </p>

<p><code>while($row = $result -&gt; fetch_assoc()) {
    $rows[] = $row;
}</code> </p>

<p>it still doesn't work. What am I missing here?</p>