Re: error in mysqli_fetch_assoc()
Welcome back to the PHP/MySQL world! The fix is small. The OOP method on a mysqli_result object is just fetch_assoc(), not mysqli_fetch_assoc(). The mysqli_ prefix is for the procedural style. So change this:
while($row = $result->mysqli_fetch_assoc())
to this:
while($row = $result->fetch_assoc())
Or if you prefer procedural style (which might feel more familiar coming from ColdFusion), you can do:
while($row = mysqli_fetch_assoc($result))
Both do the same thing, just pick one style and stick with it. The "on string" part of the error also tells me $result might not be a result object at all. Worth adding a quick check before the loop to make sure the query actually ran:
$result = $conn->query($sql);
if ($result === false) {
echo "Query error: " . $conn->error;
} else {
while($row = $result->fetch_assoc()) {
// your table code here
}
}
That way if the query itself has a problem you'll see the actual MySQL error instead of the confusing PHP fatal. Good luck with the transition!
Subject
Written By
Posted
November 15, 2025 02:48PM
Re: error in mysqli_fetch_assoc()
February 26, 2026 12:50PM
Sorry, only registered users may post in this forum.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.