How can the concept of a data set pointer be utilized effectively in PHP while loops?

When working with large datasets in PHP while loops, it can be inefficient to store the entire dataset in memory. Instead, you can utilize a data set pointer to fetch and process data one row at a time, reducing memory usage and improving performance.

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

// Query to fetch data
$query = "SELECT * FROM table";
$result = $connection->query($query);

// Process data row by row using a while loop and data set pointer
while ($row = $result->fetch_assoc()) {
    // Process data here
    echo $row['column_name'] . "\n";
}

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