setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // provide as much protection as possible to counteract possible injection attacks $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); } catch (Exception $e) { echo "error connecting to $database \n"; echo "full error message " . $e->getMessage() . "\n"; echo "exiting\n"; exit; } echo "connected to database '$database'\n"; /* query the database */ try { $sqlQuery = 'SELECT * FROM faculty where office <= 210'; echo "query: $sqlQuery \n"; $result = $pdo->query($sqlQuery); } catch (Exception $e) { echo "error on query: $sqlQuery \n"; echo "error message: $e->getMessage \n"; echo "exiting \n"; exit; } /* report results */ while ($row = $result->fetch()) { echo $row['first'] . " " . $row['last'] . "\n"; } /* closing the database connection */ $pdo = null; echo "database connection closed\n"; ?>