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 Integrating PHP with Databases Querying the Database with PHP Integrating Database Results

Why was PDO::FETCH_ASSOC removed ?

In the last video we were told to use PDO::FETCH_ASSOC to turn the array into an associate array, but all of a sudden it dissappeared.

Shouldn't the code be like this????

$catalog = $result->fetchAll(PDO::FETCH_ASSOC);

It seems to work both ways:

  1. Fetch Associative $catalog = $results->fetchAll(PDO::FETCH_ASSOC); // fetches only the associative array
  2. Fetch Both $catalog = $results->fetchAll(); // same as default of $fetchAll(PDO::FETCH_BOTH); // Does this mean our query is doing twice the work since it's searching thru both indexed and associative array? I am wondering if there one way is more correct than the other?

2 Answers

I assume you are talking about the challenge. I thnk this is because there is a defalt fetch style witch is Fetch_ASSOC

I think @jaycode is talking about the videos, I just noticed it too. At 3:10min in the previous video, Alena used the PDO::FETCH_ASSOC style to retrieve the results but it disappears by 1:20min in the current video. The default style is PDO::FETCH_BOTH.

I'm not sure why it was removed either - perhaps it was only there in the first place just to demonstrate fetch styles(?). At this stage the code seems to work with either though.

Alena Holligan .- Why was PDO::FETCH_ASSOC removed? You never showed this step. Does this mean that when we now fetch the catalog that it's doing twice the work? Since it's fetching both an associative array and also an indexed array?