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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:38:16
Original
908 people have browsed it

使用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;

Related labels:
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template