Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.