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 trialSiraj 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
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
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
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
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.