$sql = "SELECT * FROM customers"; $result = mysqli_query($conn, $sql); // Get all rows from the result set $rows = mysqli_fetch_all($result, MYSQLI_ASSOC); // Print the result print_r($rows);
$sql = "SELECT name, age FROM users WHERE city='New York'"; $result = mysql_query($sql); // Get all rows from the result set $rows = mysql_fetch_all($result, MYSQL_ASSOC); // Loop through each row and print the name and age foreach($rows as $row) { echo $row["name"] . ", " . $row["age"] . "\n"; }This example retrieves all rows from the "users" table where the city is "New York" and prints the name and age of each user. `mysql_fetch_all` is used to fetch all rows from the result set and store them in an array. Package library: mysql (Note: mysql is deprecated in PHP 5.5.0 and removed in PHP 7.0.0. Use mysqli or PDO_MySQL instead.)