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 trialVolodymyr Danileichenko
7,354 Pointsquery() method issue
I'm using MySQL and the try/catch construction from the video doesn't work. $db -> query() method returns boolean. So the code is executed in any case. It just returns "false" in case of an error. Is it a correct behaviour or am I doing something wrong? Thanks
2 Answers
Simon Coates
28,694 PointsDoes the code you include to get a connection include
$pdoObj->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
? I think Alena said that you had to tell it to throw exceptions.
Alex Roberts
Front End Web Development Techdegree Student 255 Pointstry wrapping the Media word in these ``
Like this -
try {
$db->query("SELECT title, category FROM Media
");
} catch (Exception $e) {
echo "Bad query";
}
Simon Woodard
6,545 PointsSimon Woodard
6,545 PointsPerhaps you could post the code you've written so we have a better idea of the issue.