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 Integrating PHP with Databases Querying the Database with PHP Working with Query Results

2,919 Points

getting an parse error for my var_dump

My error: Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ',' or ')' in /home/treehouse/workspace/inc/connection.php on line 16

My Code: <?php try { $db = new PDO("sqlite:".DIR."/database.db"); $db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); } catch(Exception $e) { echo "unable to connect."; echo $e ->getMessage(); exit;} try{ $results = $db ->query("SELECT title, category, img FROM Media"); echo "Retrieved Results";

} catch (Exception $e) {echo "unable to retrieve results"; exit;}

var_dump(Sresults ->fetchAll(PDO::FETCH_ASSOC)); ?>

1 Answer

Benjamin Larson
Benjamin Larson
34,055 Points

It's likely caused because you have 3 instances where you have a space between a variable and the object operator (->).

$e ->getMessage
$db ->query
$results ->fetchAll

Try removing the space from those and see what results you get.

2,919 Points

oh no i found it. It was the Sresults! I was using a capital s instead of $. XD