Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7739235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:28:21+00:00 2026-06-01T08:28:21+00:00

While writing a login system for a web project Im working on I came

  • 0

While writing a login system for a web project Im working on I came across the problem of binding an unknown number of parameters and found this function on the php manual pages. I always like to fully understand an peice of code I put into anything Im working on and Im quite stumped as to how a few sections of this function work.

Ive commented everything I think i understand(if im wrong please let me know) and left my major questions in the comments:

<?php
    function getresult($stmt) {

        //Define var for holding the result
        $result = array();

        //asign metadata of the statments result
        $metadata = $stmt->result_metadata();

        //grab the feilds from the metadata and assign to var
        $fields = $metadata->fetch_fields();

        //for loop with internal break
        for (;;) {

            //pointers array (not sure why this is an array and not a stdClass)
            $pointers = array();

            //row empty class
            $row = new stdClass();


            //set pointers array to the value of the passed statement (casting $pointers to mysqli_stmt class I assume(?)   
            $pointers[] = $stmt;

            //iterate through all fields
            foreach ($fields as $field) {
                //each time set $fieldname to the name from the current element of $fields
                $fieldname = $field->name;

                //?? this is my big issue no idea whats going on here $row hasnt been set from what i can see, and no idea why its being refered to by reference and not value
                $pointers[] = &$row->$fieldname;
            }

            //call bind result for all values
            call_user_func_array(mysqli_stmt_bind_result, $pointers);

            //internal break if 
            if (!$stmt->fetch()) {

                //if there is nothing left to fetch break
                break;
            }

            //set the result
            $result[] = $row;
        }

        //free resources
        $metadata->free();

        //return result
        return $result;
    }
?>

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T08:28:22+00:00Added an answer on June 1, 2026 at 8:28 am

    It creates a new stdClass (pretty much like an empty array) for each row.

    With $pointers[] = &$row->$fieldname; a reference to the various fields of the object is stored.

    After that, mysqli_stmt_bind_result is used to tell mysqli where to store the data of the next row. When calling $stmt->fetch(), mysqli assigns it to the references in $pointers and thus to the fields in the $row object.

    $pointers is an array because mysqli_stmt_bind_result expects one. Objects do not have 0..n fields but rather named values – so to assign columns based on their position using a non-associative array makes much more sense.


    It does pretty much the same what mysqli::fetch_object() does.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've come across an issue while I was writing a utility to scrape a
I am facing one problem while writing one xslt: xml: <students> <studentDetails tag=to id=1
I have an external JavaScript in an asp.net 3.5 project. While writing different functions,
While writing some C code, I decided to compile it to assembly and read
While writing code in a file that would comprise of PHP, HTML, CSS &
While writing code, it is pretty common to request a page with an appended
While writing a card shuffling algorithm I realized that there are 52! ~= 2^225
While writing a .jsp file, can i include all the html5 tags in it
While writing selenium testcases for a webapplication I'm having trouble with the xpath selector.
While writing some views to respond to ajax requests i find it somewhat strange

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.