我正在尝试将一些使用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}]}
答案 0 :(得分:3)
您尝试执行的操作与此相同(除了包含大量无关代码):
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