php中mysql_fetch_assoc()和mysql_fetch_array()及mysql_fetch_row()、mysql_fetch_object

WBOY
Release: 2016-07-25 08:58:24
Original
1000 people have browsed it
本文介绍下,php中的mysql操作函数mysql_fetch_assoc()、mysql_fetch_array()、mysql_fetch_row()、mysql_fetch_object()在用法上的区别。供大家参考。

相同点:三个函数都是返回数据库中查询到的一行数据(即一条数据)。 不同点:mysql_fetch_assoc()用的是数据库中相应的字段名作为的key值(也就是数组下标)如:filed['id']=1;

mysql_fetch_row()用的是自动生成的数字(从0开始依次生成)作为的key值(也就是数组下标)如:filed[0]=1; mysql_fetch_array()用的是自动生成的数字(从0开始依次生成)作为的key值(也就是数组下标),而且它还同时生成数据库中相应的字段名作为的key值(也就是数组下标)。

如:filed[0]=1,filed['id']=1; 即mysql_fetch_array()将mysql_fetch_assoc()和mysql_fetch_row()查询到的结果合为一体。 mysql_fetch_object()与mysql_fetch_assoc()差不多。 只是mysql_fetch_assoc()返回的是数组。 mysql_fetch_object()返回的是object对象。

希望大家仔细体会上面的对比分析,以便于掌握它们的区别与具体应用场景。



source:php.cn
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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!