PHP Using PHP with MySQL Querying the Database with PHP Querying the Database

Querying the Database

I'm currently working on this database and I'm fully connected yet once I get to the second try block my page is empty

<?php 



try {
$db = new PDO("mysql:host=localhost;dbname=shirts4mike;port=8889", "root", "root");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->exec("SET NAMES 'utf8'");
} catch(Exception $e) {
    echo "Could not connect to the database.";
    exit;
}



try {
    $results = $db->query("SELECT name, price FROM products")
    echo "Our query ran successfully.";
} catch(Exception $e) {
    echo "Data could not be retrieved from the database."
    exit;
}

Any suggestions

2 Answers

It looks like you don't have error reporting turned on - otherwise this would come back at you and say 'syntax error' instead of a blank page. As well as the semi-colon Amanda Field mentioned, you're also missing a semicolon from the first line in your second try block.

Try throwing:

<?php

ini_set('display_errors', 'On');
error_reporting(E_ALL);

at the top of your script.

You are missing a semicolon following the last echo.