mysqli_fetch_assoc()返回null [关闭]

this is my codes

$connect=dbConfig();
$query="SELECT * FROM comments WHERE post_id=$postId";
$res=mysqli_query($connect,$query);
$sum=[];
while ($row=mysqli_fetch_assoc($res));
{
    $sum[]=$row;
}
    return $sum;

when I call this function this function return me null

but if I use this code

$connect=dbConfig();
$query="SELECT * FROM comments WHERE post_id=$postId";
$res=mysqli_query($connect,$query);
$row=mysqli_fetch_assoc($res);
return $row;

function return me value

and this is a picture of my table in MySQL an image of my table in MySql

There is a ; after while statement. Remove it and it should be fine. The second code is alright. If you want to use another method, you can use mysqli_fetch_row().

while ($row=mysqli_fetch_row($res))
{
    $sum[]=$row;
}