PHP PHP & Databases with PDO PDO Database Security PHP & Databases with PDO

Robert Valencia
PRO
Robert Valencia
Pro Student 3,618 Points

What am I missing? The error I’m getting is that there is no Exception class

I’ve watched the video, checked my Workspace, researched online for other examples and read through the documentation, and I still can’t figure out what I’m doing wrong.

index.php
<?php

//Place your code below this comment
try{
  $db = new PDO('sqlite::memory'); 
  $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(Exception $e) {
  echo $e->getMessage; 
}

?>

2 Answers

Both of your Exception answers are good, but I guess the quiz expects a simpler response. This works for me:

try {
       // your code; 

} catch(Exception $e) {
  echo "error"; 
}

Team Treehouse, "There is no Exception class" is not helpful.

Robert Valencia
Robert Valencia
Pro Student 3,618 Points

Thank you, I believe my answer ended up being like this. :) I appreciate your help!

<?php
try{
  $db = new PDO('sqlite::memory'); 
  $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
  echo $e->getMessage; 
}

It should be PDOException

Robert Valencia
Robert Valencia
Pro Student 3,618 Points

Thanks, I had tried this too, and it should’ve taken it in my opinion. But as Remylus mentioned, the quiz expected a simpler answer.