Irrespective of @YourCommonSense's change of "object" to "row" in the title (which I feel makes the title less specific in an unhelpful way), the dupe target is asking how to fetch the entire result set as an array of objects.
@oaziz explains in the question that they already know how to fetch a single row as a flat object with fetch_object()
. Then they explain that they are currently using a fetch_object()
inside of a while()
loop to generate the desired array of objects. Then they ask if mysqli has a more direct way to fetch all rows as an array of objects -- something like fetch_objects()
.
This question is very clearly asking if php/mysqli offers a native way to fetch all rows as an object array.
The new question from @AbdulwahabAlmestekawy is using the procedural syntax (mysqli_fetch_object
) in a loop to make an array of objects and is also asking if php/mysqli offers a native way to generate an array of objects from the result object.
Because both questions are clearly asking for the exact same technique/result, closure is appropriate.
- The new Q wants
$arr_objects
as an array of objects.
- The old Q wants
$comments
as an array of objects.
The answer from @pilcrow is correct, appropriate, and is the top sorted answer -- this makes good advice easy to find when researchers arrive at the page. The dupe target is not "bad" for researchers. If editing the question will improve its searchability, I would support that (I may end up doing an edit after this meta discussion cools down anyhow).
I find @KyleNoland's answer to be too distant from resolving the asked question. I have voted to delete this unhelpful answer.
As I mentioned in my chat conversation with @Dharman, I often find suitable dupes to close new questions where the dupe target does not contain what I feel is the "best" answer -- this does not prevent me from closing the new question. In fact, I like finding older pages where the insights are suboptimal -- it means that I finally found a question that I can post an answer on. In these situations, I close the new page, answer the dupe target with suitable clarity/explanation to resolve both questions, then proceed to edit the question and critique all other answers/comments on the page to best serve future researchers.
@Dharman's advice is 100% suitable on the dupe page without any adjustment. I'd argue that it would become the new "best" answer on the dupe target.
@Phil's answer on the new question is less helpful since it is a looped/non-native equivalent of the asker's code, but it too could be safely transferred to the dupe target.
After @YourCommonSense reopened the page, I knew I could not rehammer, so I asked if @Dharman would rehammer or even merge the two identical pages. He refused because he was involved in the new page as an answer (obviously) and didn't want to appear unethical.
I believe the best outcome for the new page would be that:
- The question remain positively scored to become a signpost for the dupe target.
- @Dharman delete his answer on the new page, post it as an answer on the dupe target, then close the new page.
- @Phil's answer, too, can be deleted and posted on the dupe page.
This is a better outcome than merging the pages (which is a bit of a kludge) because the one topic now retains two access points for researchers and all answers would be in one place so that scores and sorting are simplest for researchers.
There is nothing stopping anyone from doing this immediately because:
- There is no green tick on the new question.
- @Dharman will no longer appear unethical for hammering a page where he has answered.
None of these actions do harm or punish any users. These actions prioritize Stack Overflow content curation for the betterment of the Researcher eXperience. If I were in @Dharman's position I would take the earlier described actions myself without any prompting. It just makes logical sense to me. Not #SOReadyToHelp but #ReadyToHelpSO
$result->fetch_objects()
. Both questions are seeking the exact same resultant structure. I explain this in my answer below.