gpt4 book ai didi

php - 使用 mysqli 检索数组

转载 作者:太空宇宙 更新时间:2023-11-03 12:09:27 25 4
gpt4 key购买 nike

我正在尝试将一些使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com