Home  >  Article  >  Backend Development  >  用mysqli的bind_result获取所有结果集的疑惑.

用mysqli的bind_result获取所有结果集的疑惑.

WBOY
WBOYOriginal
2016-06-06 20:36:492348browse

<code> if($result instanceof mysqli_stmt)
    {
        $result->store_result();

        $variables = array();
        $data = array();
        $meta = $result->result_metadata();

       // 从这里开始就迷糊
        while($field = $meta->fetch_field())
            $variables[] = &$data[$field->name]; // pass by reference

        call_user_func_array(array($result, 'bind_result'), $variables);

        $i=0;
        while($result->fetch())
        {
            $array[$i] = array();
            foreach($data as $k=>$v)
                $array[$i][$k] = $v;
            $i++;
        }
    }
</code>

上面的代码中$variables是一个索引为数字的空数组啊,怎么绑定上的。。最好解释一下为什么这么写?感激不尽。

回复内容:

<code> if($result instanceof mysqli_stmt)
    {
        $result->store_result();

        $variables = array();
        $data = array();
        $meta = $result->result_metadata();

       // 从这里开始就迷糊
        while($field = $meta->fetch_field())
            $variables[] = &$data[$field->name]; // pass by reference

        call_user_func_array(array($result, 'bind_result'), $variables);

        $i=0;
        while($result->fetch())
        {
            $array[$i] = array();
            foreach($data as $k=>$v)
                $array[$i][$k] = $v;
            $i++;
        }
    }
</code>

上面的代码中$variables是一个索引为数字的空数组啊,怎么绑定上的。。最好解释一下为什么这么写?感激不尽。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn