Home > Article > Backend Development > php中mysql_fetch_assoc()和mysql_fetch_array()及mysql_fetch_row()、mysql_fetch_object
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. |