PHP Designing Interfaces in PHP Introducing Interfaces Implement MySQL RepositoryInterface

I'm not sure what I'm missing here...

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.

Was this covered in the video?

Some help would be much appreciated. TIA

sqlRepository.php
<?php

class sqlRepository extends PDO implements RepositoryInterface {

public function all();{
  return fetchAll(PDO::FETCH+OBJ); 
}

    }

<?php

class sqlRepository extends PDO implements RepositoryInterface {

public function all() { return fetchAll(PDO::FETCH_OBJ); }

}

2 Answers

Felipe Giovanni de Moura Santos
Felipe Giovanni de Moura Santos
19,210 Points

You didn't tell the database what you want, just how you want it. You need to query the db and then "fetchAll" the result.

I didn't take this course yet, but you'll find one possible answer here: https://teamtreehouse.com/community/challenge-task-2-makes-no-sense-what-is-the-name-of-the-mysql-database-table-passed-to-the-method

razmig pulurian
PRO
razmig pulurian
Pro Student 22,402 Points

I too got stuck on this challenge. According to the post linked by Felipe Giovanni de Moura Santos, we ought to be defining what we want with something like :

$db = new PDO("sqlite:".__DIR__."/database.db");
$query = $db->query("SELECT * FROM ".$entity);

But I think the O.P. is correct in saying that the instructor did not cover this material before this point. I think the instructor never introduced what an SQL query even is, let alone how to write one. I skimmed through all of the videos in the Beginning PHP and OOP PHP tracks leading up to this challenge, and I could not find any examples of how to write an SQL query.

Judging by colorful (read: frustrated) posts from other treehouse users here (for example this post and this one too) it seems like we aren't the only ones that the instructor did not introduce this material. (I'd be happy to be proven wrong though!)

This PHP course is doing a good job of making me feel dumb. :(