mysql_fetch_row()vs mysql_fetch_assoc()vs mysql_fetch_array() [英] mysql_fetch_row() vs mysql_fetch_assoc() vs mysql_fetch_array()
问题描述
可能重复:
mysql_fetch_array,mysql_fetch_assoc,mysql_fetch_object
Possible Duplicate:
mysql_fetch_array, mysql_fetch_assoc, mysql_fetch_object
我想要一个可以将结果集当前行中的字段返回到关联数组并将结果指针移至下一行的函数.
I want a function which can return fields in the current row of a resultset into an associative array and moves the result pointer to the next row.
困惑
mysql_fetch_row()
mysql_fetch_assoc()
mysql_fetch_array()
我应该使用哪个?任何帮助,将不胜感激. 谢谢.
Which one should I use? Any help would be appreciated. Thank you.
推荐答案
注意:
>功能被认为已被弃用,而您应该使用具有更好安全性和更多功能的东西,例如 MySQLi 或
Note: The use of the
mysql_*
functions are considered deprecated and you should instead use something that offers better security and more functionality, such as MySQLi or PDO.
这是什么?
您正在寻找 mysql_fetch_assoc
作为名称表示将返回一个关联数组(以列名作为键,值作为行值).
What is it?
You are looking for mysql_fetch_assoc
, as the name implies it will return an associative array (with the column names as keys and the values as the row values).
所有提到的函数将返回一个数组,它们之间的区别是返回的对象中用作键的值.
All of the mentioned functions will return an array, the differences between them is what values that are being used as keys in the returned object.
此函数将返回一行,其中值将按照在SQL查询中定义的顺序排列,并且键的范围从0
到小于所选列数的一.
This function will return a row where the values will come in the order as they are defined in the SQL query, and the keys will span from 0
to one less than the number of columns selected.
此函数将返回一行作为关联数组,其中列名将是存储相应值的键.
This function will return a row as an associative array where the column names will be the keys storing corresponding value.
此函数实际上将返回一个数组,其中mysql_fetch_row
和mysql_fetch_assoc
的内容都合并为一个.它都具有数字和 string 键,可让您以最容易找到的任何方式访问数据.
This function will actually return an array with both the contents of mysql_fetch_row
and mysql_fetch_assoc
merged into one. It will both have numeric and string keys which will let you access your data in whatever way you'd find easiest.
尽管如此,还是建议使用_assoc
或_row
.
It is recommended to use either _assoc
or _row
though.
这篇关于mysql_fetch_row()vs mysql_fetch_assoc()vs mysql_fetch_array()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!