Search code examples
phpmysqlmysqli

Select * in a remote DB (MySQL) doesn't bring all the data


The query is simple -> "SELECT * FROM xxx";

When the result comes, it brings only the last result of the table instead all.

If I'm not mistaken, most remote databases come with a limit on the amount of data that is fetched, in order to avoid overflowing results. But none of that is for sure, just my speculation. Anyway, how to solve this?

$stmt = mysqli_stmt_init($conn);

$sql = "SELECT * FROM favorite";

mysqli_stmt_prepare($stmt, $sql);

mysqli_stmt_execute($stmt);

$result = mysqli_stmt_get_result($stmt);

$row = mysqli_fetch_assoc($result);

var_dump($row);

Solution

  • Try

    $row = mysqli_fetch_all($result);
    
    mysqli_fetch_assoc();
    

    only returns 1 row which explains why you only see the last row of the expected result set.

    mysqli_fetch_all