Heim  >  Artikel  >  Backend-Entwicklung  >  用mysqli的bind_result获取所有结果集的疑惑.

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

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

<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是一个索引为数字的空数组啊,怎么绑定上的。。最好解释一下为什么这么写?感激不尽。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn