Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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.