<?php
# Performs the given SQL query using PDO and returns the resulting rows.
# Displays an error message if the query fails.
function perform_query($query) {
  try {
    $db = new PDO("mysql:host=localhost;dbname=world", "traveler", "packmybags");
    $rows = $db->query($query);
    return $rows;
  } catch (PDOException $ex) {
    ?>
    <p>Sorry, a database error occurred.</p>
    <?php
    return NULL;
  }
}
?>
