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

PHP

Kyle Peterson
PLUS
Kyle Peterson
Courses Plus Student 2,118 Points

Can't solve 'Implement MYSQL RepositoryInterface' objectives. is this a bug?

I’m struggling to solve this problem under 'Implement MYSQL RepositoryInterface'.

Link to challenge (task 2 of 3)

The question and my code is as follows:

Question:

Challenge Task 2 of 3 Define the "all" method to return all items from the MySQL database table passed to the method. Use "fetchAll(PDO::FETCH_OBJ)" to return the results as an array of objects.

Code:

<?php

class sqlRepository extends PDO implements RepositoryInterface
{
  private $pdo = null;
  public function __construct($dsn)
  {
    try {
      parent::__construct($dsn);
    } catch (\PDOException $e) {
      echo $e->getMessage();
    }
  }
  public function all($table)
  {

    //$this->posts = $table;
    //var_dump($table);
    $stmt = $this->query('SELECT * FROM '.$table);
   // $stmt = $this->prepare('SELECT * FROM ?');
    //$stmt->bindValue(1, $this->posts);
    var_dump($stmt);

   // $stmt->execute(array(1, $this->posts));
    //$stmt = $this->query("SELECT * FROM posts");
    $results = $stmt->fetchAll(PDO::FETCH_OBJ);
    var_dump($results);
    return $results;
  }

}
// var_dump(scandir(__DIR__));

Everytime I try to prepare a statement with the $table parameter the pdo statement returns a false bool. Concatenating the variable with the query seems to return the expected result from the db but whenever I check the work I get this weird feedback:

“Bummer: Argument 1 passed to enroll() must be an instance of Student, string given </span></pre>”

Is this a bug? Or am I doing something wrong here? Any help would be greatly appreciated.