我正在尝试将一些使用mysql的旧php代码转换为使用mysqli,

我更新到的代码是:

function mysql_fetch_full_result_array($result){
global $dbc;

    $table_result=array();
    $r=0;
    while($row = mysqli_fetch_assoc($result)){
        $arr_row=array();
        $c=0;
        while ($c < mysqli_num_fields($result)) {
            $col = mysqli_fetch_field($result);
            $arr_row[$col -> name] = $row[$col -> name];
            $c++;
        }
        $table_result[$r] = $arr_row;
        $r++;
    }
    return $table_result;
}


但是,在第一行之后,它只为每个值输出null(如此处所示),我确定我没有增加任何值,但是我不确定此时在哪里或如何:

{"DOMAIN.COM":[{"image":"http:\/\/DOMAIN.COM\/photos\/grid_logo.jpg","source":"logo","user":"","printed":"","note":""},{"image":"http:\/\/DOMAIN.COM\/photos\/grid_block.jpg","source":"block","user":"","printed":"","note":""},{"image":"http:\/\/pbs.twimg.com\/media\/BlNvdcrCAAAlz8-.jpg","source":"twitter","user":"ObserveMeditate","printed":"0","note":"RT @IMSEngage: Moby (@thelittleidiot) sits down with the legendary @DAVID_LYNCH this Wednesday: http:\/\/t.co\/PMn9EHQVcp #IMSEngage http:\/\/t.\u2026"},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null},{"image":null,"source":null,"user":null,"printed":null,"note":null}]}

最佳答案

看来您尝试做的事情与此相同(除非有很多无关的代码):

while($row = mysqli_fetch_assoc($result)) {
    $table_result[] = $row;
}
return $table_result;


或许:

while($row[] = mysqli_fetch_assoc($result)) { }
return $row;


甚至只是:

$all_rows = mysqli_fetch_all($result, MYSQLI_ASSOC); //may still be server dependent

关于php - 使用mysqli检索数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25023992/

10-13 09:41