相同点:php中php中mysqli_fetch_assoc()与mysqli_fetch_row()都是把查询结果的第一行返回到一个数组中。
不同点:
mysqli_fetch_row是通过数字索引取值。例如:
$res=mysqli_query($con,$sql);//返回的资源
$arr=mysqli_fetch_row($res);//把查询结果的第一行返回到$arr 数组中
print_r($arr);
print_r($arr[0]);//通过索引取值

然而mysqli_fetch_assoc()用关键字索引取值。比如:
$res=mysqli_query($con,$sql);//返回的资源
$arr=mysqli_fetch_assoc($res);
print_r($arr);
echo $arr['people'];
本文介绍了 PHP 中使用 mysqli_fetch_assoc() 和 mysqli_fetch_row() 方法从 MySQL 数据库查询结果中获取数据的不同方式。mysqli_fetch_row() 通过数字索引访问数据,而 mysqli_fetch_assoc() 则通过字段名称作为关键字来访问。
554

被折叠的 条评论
为什么被折叠?



