mysql_fetch_array是mysql_fetch_assoc和mysql_fetch_row的组合吗?

时间:2013-09-04 07:57:04

标签: php mysql database arrays

我一直在阅读有关mysql_fetch_ *方法的内容。 这是我从PHP.org网站上学到的。

mysql_fetch_array — Fetch a result row as an associative array, a numeric array, or both
mysql_fetch_assoc — Fetch a result row as an associative array
mysql_fetch_object — Fetch a result row as an object
mysql_fetch_row — Get a result row as an enumerated array

看起来mysql_fetch_array包含

中存在的所有值

mysql_fetch_assoc,mysql_fetch_object,mysql_fetch_row。因为mysql_fetch_assoc仅包含关联数组,

mysql_fetch_row包含数字数组中的数据。

mysql_fetch_object也会返回关联数组。

请告诉我,我的理解是正确还是错误。

1 个答案:

答案 0 :(得分:4)

mysql_fetch_assoc返回一个关联数组,mysql_fetch_row返回一个数值数组,使用mysql_fetch_array可以选择输出结果。此函数接受可选参数,该参数可以取值:

  • MYSQL_ASSOC - 返回关联数组
  • MYSQL_NUM - 返回数值数组
  • MYSQL_BOTH - 返回组合数字和关联数组

最后一个值是默认值。

mysql_fetch_object略有不同,因为它返回的对象的字段对应于从数据库中获取的结果中的列。

作为旁注,我想补充一点,mysql_*函数已弃用,您应该切换到mysqli或PDO。

相关问题