// Connect to database using PDO $db = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password'); // Prepare and execute query $stmt = $db->prepare("SELECT * FROM users"); $stmt->execute(); // Fetch resultset as associative array $resultSet = $stmt->fetchAll(PDO::FETCH_ASSOC); // Loop through resultset and output data foreach ($resultSet as $row) { echo $row['name'] . ' - ' . $row['email'] . 'In this example, we are using the PDO library to connect to a MySQL database, prepare and execute a query to select all users from the "users" table, and then fetch the resultset as an associative array. We can then iterate over the resultset using a foreach loop to output each user's name and email address. Overall, the PDO library provides a secure, efficient, and easy-to-use interface for querying databases in PHP.
'; }