This article mainly shares with you the usage and differences of fetch for PHP query data. There are four kinds of fetch usage and differences. I hope it can help everyone.
mysql_fetch_row;
mysql_fetch_array;
mysql_fetch_assoc;
mysql_fetch_object;
1.mysql_fetch_row;
Every time mysql_fetch_row is executed, a piece of data is taken out from the resource result set. Return it as an array.
#The returned array is a one-dimensional index array, and each subscript corresponds to the sorting of the fields in the database.
##2.mysql_fetch_array();
The difference between mysql_fetch_array and mysql_fetch_row:
1, mysql_fetch_row is executed once to generate an index array;
2, mysql_fetch_array is in the default state Take a piece of data to generate an index array and associative array
/********
mysql_fetch_array has a second parameter
1, MYSQL_ASSOC-Associative array
2. MYSQL_NUM- Numeric array (index array)
3. MYSQL_BOTH- Default state (both index array and associative array are displayed)**************/
Default state The index array and associative array are displayed below
##3.mysql_fetch_assoc();
Only display associative arrays
##4, mysql_fetch_object
The displayed data is an object.
Related recommendations:
Detailed explanation of PHP’s mysql_fetch series functions
The above is the detailed content of The usage and difference of fetch in php query data. For more information, please follow other related articles on the PHP Chinese website!