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!

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 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

Clare A
Clare A
23,994 Points

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?