What are the different methods in PHP to fetch and store all results from a MySQL query without using individual variables?

When fetching and storing all results from a MySQL query in PHP without using individual variables, you can use the fetch_all() method along with the MYSQLI_ASSOC constant to fetch all rows as an associative array. This method allows you to store all results in a single variable without the need for individual variables.

// Connect to MySQL database
$mysqli = new mysqli("localhost", "username", "password", "database");

// Check connection
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
}

// Perform query and fetch all results
$query = $mysqli->query("SELECT * FROM table");
$results = $query->fetch_all(MYSQLI_ASSOC);

// Display results
foreach ($results as $row) {
    echo $row['column_name'] . "<br>";
}

// Close connection
$mysqli->close();