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

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
23,702 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

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. :(