Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Designing Interfaces in PHP Introducing Interfaces Implement MySQL RepositoryInterface

problem with prepare statement PDO

In function find, although I used prepare statement, when I click button "Recheck work", the app still announce an error: "make sure you use prepared statement". I truly don't understand how. Please help me


class sqlRepository extends PDO implements RepositoryInterface{
  protected $db;

  public function __construct($file){
      $this->db = new PDO("sqlite:" . __DIR__ . "/database.db");
      $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    }catch (Exception $e){
      echo "Unable to connect";

  public function all($tableName){
    try {
      $results = $this->db->query("SELECT * FROM $tableName");
      return $results->fetchAll(PDO::FETCH_OBJ);
    } catch (Exception $e) {
      echo "Unable to retrieved results";

  public function find($entity, $value, $field = 'id'){
    $statement = $this->db->preapre("SELECT * FROM :entity WHERE :field = :value");
    $statement->bindParam(':entity', $entity, PDO::PARAM_STR);
    $statement->bindParam(':field', $field, PDO::PARAM_STR);
    $statement->bindParam(':value', $value, PDO::PARAM_STR);
    return $statement->fetchAll(PDO::FETCH_OBJ);


1 Answer

Sorry all, I found my problem: I typed wrong word "prepare". I also follow the question https://teamtreehouse.com/community/im-stumped-on-this-one to solve my problem Thanks all :)