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

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

WBOY
Release: 2016-06-06 20:36:49
Original
2405 people have browsed it

<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>
Copy after login
Copy after login

上面的代码中$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>
Copy after login
Copy after login

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

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template