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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Siraj Khan](https://secure.gravatar.com/avatar/57219d6f4c02b2c509be1c9170c33c67?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Siraj Khan
3,451 PointsWhat is wrong with my code.? Please help.
Why do I see only "Unable to retrieve results".? Even that everything is in place. Below is 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 {
$reults = $db-> query("SELECT title, category FROM Media");
echo "Retrieved Results";
} catch (Exception $e) {
echo "Unable to retrieve results";
exit;
}
3 Answers
![Jonathan Grieve](https://uploads.teamtreehouse.com/production/profile-photos/601842/micro_twitterCover.png)
Jonathan Grieve
Treehouse Moderator 91,253 PointsIt looks like you haven't chained your query to the database properly. Also try fixing the results variable to say $results
which I'm presuming is a typo.
So
<?php
$reults = $db-> query("SELECT title, category FROM Media");
?>
becomes
<?php
$results = $db->query("SELECT title, category FROM Media");
?>
I think PHP is thinking they're 2 separate statements. :-)
![Siraj Khan](https://secure.gravatar.com/avatar/57219d6f4c02b2c509be1c9170c33c67?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Siraj Khan
3,451 PointsHowever I see this long error/Warning message in phpMyAdmin: "Warning in ./libraries/classes/Dbi/DbiMysqli.php#213 mysqli_query(): (HY000/1682): Native table 'performance_schema'.'session_variables' has the wrong structure"
I don't understand what's going on.! Please help
![Jonathan Grieve](https://uploads.teamtreehouse.com/production/profile-photos/601842/micro_twitterCover.png)
Jonathan Grieve
Treehouse Moderator 91,253 PointsAre you still getting the "unable to retreve results" error? Because that message suggests that you are at least getting a conenction to the database.
Try uncommenting and adding the following code to your try blocks
// echo $e->getMessage();
I suspect then the next thing to try would be to check you're making the right query to the database. :-)
Good luck!
![Siraj Khan](https://secure.gravatar.com/avatar/57219d6f4c02b2c509be1c9170c33c67?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Siraj Khan
3,451 PointsI tried uncommenting echo $e->getMessage();
and I still get the same thing in the browser i.e. "unable to retrieve results".!
What do you mean by "making the right query to the database".??
Siraj Khan
3,451 PointsSiraj Khan
3,451 PointsHey Jonathan Grieve ,
What do you mean by "It looks like you haven't chained your query to the database properly" .?
And I tired this as well:
But nothing seems to work.