$query = "SELECT * FROM users"; $results = mysqli_query($connection, $query); // iterate through results while ($row = mysqli_fetch_assoc($results)) { echo $row['username']; }
$query = "SELECT name, email FROM customers"; $results = $pdo->query($query); // iterate through results while ($row = $results->fetch(PDO::FETCH_ASSOC)) { echo $row['name'] . ", " . $row['email']; }This code selects the "name" and "email" fields from the "customers" table and returns a result set that can be iterated through using a while loop. The PDO::query function is used to execute the query and the PDOStatement::fetch function is used to retrieve each row of data. Package library: PDO