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 Designing Interfaces in PHP Introducing Interfaces Implement MySQL RepositoryInterface

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

Can't create parameterized query.

The code I have commented out causes a fatal error. However, if I enter the table name directly instead of passing it, the code executes and displays all the information in the posts table. But when I check my work it says its incorrect and leaves an unhelpful hint...

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

sqlRepository.php
<?php

class sqlRepository extends PDO implements RepositoryInterface
{
  public function __construct($dsn)
  {
    try {
      parent::__construct($dsn);
      //echo 'it worked';
    } catch (\PDOException $e) {
      echo $e->getMessage();
    }
  }
  public function all($table)
  {
    // $stmt = $this->prepare('SELECT * FROM ?');
    // $stmt->bindValue(1, $table);
    // $stmt->execute();
    $stmt = $this->query("SELECT * FROM posts");
    $results = $stmt->fetchAll(PDO::FETCH_OBJ);
    var_dump($results);
    return $results;
  }

}
//var_dump(scandir(__DIR__));