教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php中mysql_fetch_assoc()和mysql_fetch_array()及mysql_fetch_row()、mysql_fetch_object

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

发布时间:2016-06-24   编辑:jiaochengji.com
本文介绍下,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对象。

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

您可能感兴趣的文章:
php中mysql_fetch_assoc()和mysql_fetch_array()及mysql_fetch_row()、mysql_fetch_object
php中执行mysql查询的步骤与方法
php mysql_fetch_array与mysql_fetch_assoc区别
php中mysql_fetch_array()函数的用法
php数据库操作代码大全
PHP 操作MYSQL基础知识
一个php连接mysql数据库的类
一个php调用数据库的类
Warning: mysql_fetch_assoc() expects parameter 1 to be resource解决方法
php中mysql_fetch_array()和mysql_fetch_rows()函数区别

[关闭]
~ ~