Home >php教程 >php手册 >php中mysqli_fetch_assoc()和mysqli_fetch_row()的区别

php中mysqli_fetch_assoc()和mysqli_fetch_row()的区别

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 11:38:16909browse

使用mysqli_fetch_assoc()和mysqli_fetch_row()都是把查询结果返回到一个数组中,都是返回第一行然后指针下移一行。

区别:mysqli_fetch_assoc()用关键字索引取值。比如:
$row = $result->fetch_assoc();
echo $row['username'];

但是mysqli_fetch_row()用数字索引取值。比如:
$row = $result->fetch_row();
echo $row[0];//注:“0”的意思是表中的第一个字段(即username是表中的第一个字段)。

另外还有一个函数:mysqli_fetch_object()将一行取回到一个对象中,然后通过类的方式取值,比如:
$row = $result->fetch_object();
echo $row->username;

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn