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 trialjlampstack
23,932 PointsWhy 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);
2 Answers
Ryan Leenay
12,504 PointsI assume you are talking about the challenge. I thnk this is because there is a defalt fetch style witch is Fetch_ASSOC
Clare A
23,994 PointsI 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.
jlampstack
23,932 PointsAlena 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?
jlampstack
23,932 Pointsjlampstack
23,932 PointsIt seems to work both ways:
$catalog = $results->fetchAll(PDO::FETCH_ASSOC); // fetches only the associative array
$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?