Home  >  Article  >  Backend Development  >  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

WBOY
WBOYOriginal
2016-07-25 08:58:241124browse
This article introduces the differences in usage of the mysql operation functions mysql_fetch_assoc(), mysql_fetch_array(), mysql_fetch_row(), and mysql_fetch_object() in PHP. For reference.

Similar points: The three functions all return a row of data (i.e. a piece of data) queried in the database. The difference: mysql_fetch_assoc() uses the corresponding field name in the database as the key value (that is, the array subscript), such as: filed['id']=1;

mysql_fetch_row() uses automatically generated numbers (generated sequentially starting from 0) as the key value (that is, the array subscript) such as: filed[0]=1; mysql_fetch_array() uses automatically generated numbers (generated sequentially starting from 0) as the key value (that is, the array subscript), and it also generates the corresponding field name in the database as the key value (that is, the array subscript) ).

For example: filed[0]=1, filed['id']=1; That is, mysql_fetch_array() combines the results queried by mysql_fetch_assoc() and mysql_fetch_row() into one. mysql_fetch_object() is similar to mysql_fetch_assoc(). It's just that mysql_fetch_assoc() returns an array. mysql_fetch_object() returns the object object.

I hope you will carefully understand the above comparative analysis so that you can grasp their differences and specific application scenarios.



Statement:
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