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

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

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

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